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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.util.*;
import java.io.*;

public class CodeJam {
    public static void main(String[] args) {
        try {
            //recycleLarge(1000000, 2000000);
            // read
            FileInputStream instream = new FileInputStream("A-small.in");
            DataInputStream in = new DataInputStream(instream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));

            // write
            FileOutputStream outstream = new FileOutputStream("A-small.out");
            DataOutputStream out = new DataOutputStream(outstream);
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));

            // reading file information
            int testcases = Integer.parseInt(br.readLine());
            for (int i = 0; i < testcases; i++) {
                // -------------------------------------------------------------------------------------------------------------
                String line = br.readLine();
                String[] items = line.split(" ");
                int A = Integer.parseInt(items[0]);
                int B = Integer.parseInt(items[1]);
                // -------------------------------------------------------------------------------------------------------------
                bw.write("Case #" + (i + 1) + ": " + recycleLarge(A, B) + "\r\n");
            }

            // close input file
            in.close();
            // close output file
            bw.flush();
            out.close();
        } catch (Exception e) {
            System.err.println("Error: " + e.getMessage());
        }
    }

    private static int eval(int i) {
        if (i < 0)
            return 0;
        else
            return i;
    }

    private static void printArray(Object[] array) {
        for (Object ch : array)
            System.out.print(ch);
    }

    private static boolean isRecycled(String str, String m) {
        for (int i = 1; i < str.length(); i++) {
            String digits = str.substring(i) + str.substring(0, i);
            if (digits.equals(m)) return true;
        }
        return false;
    }

    private static String convertTo(int n) {
        String str = "";
        while (n != 0) {
            str = (n % 10) + str;
            n = n / 10;
        }
        return str;
    }

    private static long recycle(int A, int B) {
        long count = 0;
        for (int n = A; n < B; n++) {
            for (int m = n + 1; m <= B; m++) {
                String nstr = convertTo(n);
                String mstr = convertTo(m);
                if (isRecycled(nstr, mstr))
                    count++;
            }
        }
        return count;
    }

    private static long evaluate(int n, int A, int B) {
        String nstr = convertTo(n);
        int c = 0;
        for (int i = 1; i < nstr.length(); i++) {
            String digits = nstr.substring(i) + nstr.substring(0, i);
            int variation = Integer.parseInt(digits);
            if(digits.charAt(0) == '0') continue;
            if (digits.equals(nstr)) continue;
            if (variation <= B && variation >= A){
                visit[variation] = true;
                c++;
            }

        }
        return sum(c);
    }

    private static long sum(int n){
        return n * (n+1) / 2;
    }

    private static long recycleLarge(int A, int B) {
        long sum = 0;
        visit = new boolean[B+1];
        for(int i=0; i<B; i++) visit[i] = false;
        for (int n = A; n <= B; n++) {
            if (visit[n] == false)
                sum += evaluate(n, A, B);
        }
        return sum;
    }

    private static boolean[] visit = null;


}

