package com.menzus.gcj._2012.qualification.c;

import com.menzus.gcj.common.InputBlockParser;
import com.menzus.gcj.common.OutputProducer;
import com.menzus.gcj.common.impl.AbstractProcessorFactory;

public class CProcessorFactory extends AbstractProcessorFactory<CInput, COutputEntry> {
    public CProcessorFactory(String inputFileName) {
	super(inputFileName);
    }

    @Override
    protected InputBlockParser<CInput> createInputBlockParser() {
	return new CInputBlockParser();
    }

    @Override
    protected OutputProducer<CInput, COutputEntry> createOutputProducer() {
	return new COutputProducer();
    }
}

import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;


public class B {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		Scanner a = new Scanner(new File("/Users/anurag/Dev/Java/workspace/CodeJam/src/input"));
		FileWriter w = new FileWriter(new File("/Users/anurag/Dev/Java/workspace/CodeJam/src/output"));
		int T = a.nextInt();
		for (int t = 1; t <= T; ++t) {
			int lower = a.nextInt();
			int upper = a.nextInt();
			
			int numInversions = 0;
			for (int i = lower; i <= upper; ++i) {
				int maxPower = (int) Math.log10(i);
				int rotatedNumber = i;
				do {
					int lastDigit = rotatedNumber % 10;
					rotatedNumber = ((int) (rotatedNumber/10)) + (int) (lastDigit * Math.pow(10, maxPower));
					
					if (rotatedNumber >= lower && rotatedNumber <= upper && rotatedNumber != i) {
						++numInversions;
					}
					
				} while (rotatedNumber != i);
				
			}
			
			w.write(String.format("Case #%d: %d\n", t, numInversions/2));
		}
		
		w.close();

	}
	
	
	
	


}
