import java.io.*;
import java.util.*;

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}



///REMOVE ALL OUTPUT AND USE STRINGTOKENIZER!


/*
ID: mfranzs1
LANG: JAVA
TASK: RecycledNumbers
*/
import java.io.*;
import java.util.*;

public class RecycledNumbers {
	static BufferedReader f;
	public static void main (String [] args) throws IOException {
		long unixTime = System.currentTimeMillis();
		// Use BufferedReader rather than RandomAccessFile; it's much faster
		f = new BufferedReader(new FileReader("RecycledNumbers.in"));
	                                                  // input file name goes above
	    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("RecycledNumbers.out")));
	    // Use StringTokenizer vs. readLine/split -- lots faster
	    //StringTokenizer st = new StringTokenizer(f.readLine()," ");	    	
    	//int i = Integer.parseInt(st.nextToken());
	    
	    int cases=Integer.parseInt(f.readLine());
	    for(int c=0;c<cases;c++){
	    	StringTokenizer st = new StringTokenizer(f.readLine()," ");	
	    	int A = Integer.parseInt(st.nextToken());
	    	int B = Integer.parseInt(st.nextToken());
	    	////System.out.println(A+" "+B);
	    	int numRecycled=0;
	    	for(int n=A;n<B;n++){
	    		numRecycled+=rec(n,B);
	    	}
	    	System.out.println("Case #"+(c+1)+": "+numRecycled);
	    	out.println("Case #"+(c+1)+": "+numRecycled);
	    }
	    
	    
	    
	    out.close();                                  // close the output file
	    
	    //System.out.println("Time elapsed (ms): "+(System.currentTimeMillis()-unixTime));
	    
	    System.exit(0);                               // don't omit this!
	  }
	public static int rec(int n,int max){
		ArrayList<String> workingPairs = new ArrayList<String>();
		String stringN=""+n;
		for(int swap=1;swap<stringN.length();swap++){
			String next=stringN.substring(swap)+stringN.substring(0,swap);
			int m=Integer.parseInt(next);
			if(n<m&&m<=max&&(m+"").charAt(0)!='0'){
				String add=n+" "+m;
				if(!workingPairs.contains(add)){
					workingPairs.add(add);
				}
				//System.out.println(n+" "+m);
			}
			////System.out.println(next);
		}
		return workingPairs.size();
	}
}