package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

package cycles;

import java.io.File;

import io.Reader;

public class CycloMatic {
	public static void main(String[] args){
		new CycloMatic();
	}
	
	public CycloMatic(){
		String[] lines = Reader.getInput(new File("C-small-attempt0.in"));
		
		
		for(int i = 0; i < lines.length; i++){
			String line = lines[i];
			String[] lineParts = line.split(" ");
			int bottom = Integer.parseInt(lineParts[0]);
			int top = Integer.parseInt(lineParts[1]);
			int sum = 0;
			for(int j = bottom; j<top; j++){
				int q = numCycles(j,top);
				if (q!=0){
					sum+=q;
				}
			}
			System.out.println("Case #"+(i+1)+": "+sum);
		}
			
		
	}
	
	public int numCycles(int original, int max){
		int counter = 0;
		String newIntS = cycle(original);
		int newInt = Integer.parseInt(newIntS);
		for (int i = 0; i < (original+"").length();i++){
			if(newInt>original && newInt<=max){
				counter++;
			}
			newIntS = cycle(newIntS);
			newInt = Integer.parseInt(newIntS);
		}
		return counter;
	}
	
	
	public String cycle(int j){
		return cycle(j+"");
	}
	
	public String cycle(String j){
		String s = j+"";
		char ss=s.charAt(s.length()-1);
		s = s.substring(0,s.length()-1);
		return ss+s;
	}
}
