import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.util.Scanner;


public class GoogleNumbers {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int p = scan.nextInt();
		
		int n, m;
		for(int i = 1; i <= p; i++) {
			int total = 0;
			n = scan.nextInt();
			m = scan.nextInt();
			for( ; n < m; n++) {
				for(int j=n+1; j <= m; j++) {
					
					if(recycled(n+"",j+""))
						total++;
					
				}
			}
			System.out.println("Case #"+i+": "+total);
		}
		
		
	}
	public static boolean recycled(String n, String m) {
		char[] cN = n.toCharArray();
		char[] cM = m.toCharArray();
		
		int tot1 = 0;
		int tot2 = 0;
		for(int i = 0; i < cN.length; i++) {
			tot1+= cN[i];
			tot2+= cM[i];
		}
		if(tot1!=tot2)
			return false;
		
		
		for(int j=0; j < cN.length; j++) {
			boolean found = true;
			for(int k=0; k < cN.length; k++) {
				if(cN[k] != cM[(k+j)%cN.length]) {
					found = false;
					break;
				}
			}
			if(found)
				return true;
		}
		
		return false;
		
	}
}
