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.io.FileReader;
import java.io.LineNumberReader;
import java.io.PrintStream;

public class RecycledNumbers {
	public boolean testRecycled(int a, int b) {
		String sa = String.valueOf(a);
		String sb = String.valueOf(b);
//		if(sa.indexOf('0')!=-1 || sb.indexOf('0')!=-1)
//			return false;
		int n = sa.length();
		for(int i=0; i<n; i++) {
			StringBuffer buf = new StringBuffer();
			buf.append(sa.substring(n-1));
			buf.append(sa.substring(0,n-1));
			sa = buf.toString();
			if(sb.equals(sa))
				return true;
		}
		return false;
	}
	public static void main(String[] args) throws Exception {
		RecycledNumbers rn = new RecycledNumbers();
		LineNumberReader in = new LineNumberReader(new FileReader(args[0]+".in"));
		String line = null;
		line = in.readLine();
		if(line==null||line.length()==0)
			return;
		int T = 0;
		T = Integer.parseInt(line);
		PrintStream out = new PrintStream(args[0]+".out");
		System.out.println(new java.util.Date());
		for(int k=1; k<=T; k++){
			line = in.readLine();
			String[] data = line.split(" ");
			// brute force
			int n = 0;
			int A = Integer.parseInt(data[0]); 
			int B = Integer.parseInt(data[1]); 
			for(int i = A; i<B; i++) {
				for(int j = i+1; j<=B; j++) {
					if(rn.testRecycled(i, j))
						n++;
				}
			}
			StringBuffer buf = new StringBuffer();
			buf.append("Case #");
			buf.append(k);
			buf.append(": ");
			buf.append(n);
			out.println(buf.toString());
			System.out.println(buf.toString());
		}
		System.out.println(new java.util.Date());
		in.close();
		out.close();
	}

}
