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();
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class RecycledNumbers {
    public static void main(String[] args) {
        new RecycledNumbers().go();
    }

    private void go() {
        Scanner sc = new Scanner(System.in);

        int numTestCases = Integer.parseInt(sc.nextLine());

        for (int caseNum = 1; caseNum <= numTestCases; caseNum++) {
            System.out.print("Case #" + caseNum + ": ");
            int A = sc.nextInt();
            int B = sc.nextInt();

            long sum = 0;
            for (int n = A; n < B; n++) {
                String N = String.valueOf(n);
                for (int i = 1; i < N.length(); i++) {
                    int reCycled = Integer.parseInt(rotate(N, i));
                    if(reCycled > n && reCycled <= B)
                        sum++;
                }
            }
            System.out.println(sum);
        }
    }

    private boolean isRecycled(int n, int m) {
        if (!isPermutation(n, m))
            return false;

        String N = String.valueOf(n);
        String M = String.valueOf(m);

        for(int i = 1; i < N.length(); i++) {
            String reCycled = rotate(N, i);
            if(reCycled.equals(M)) {
                return true;
            }
        }
        return false;
    }

    public static boolean isPermutation(int n, int m) {
        int[] digitsN = new int[10];
        int[] digitsM = new int[10];

        while(n != 0) {
            digitsN[n % 10]++;
            n = n / 10;
        }

        while(m != 0) {
            digitsM[m % 10]++;
            m = m / 10;
        }

        return Arrays.equals(digitsN, digitsM);
    }

    public static String rotate(String n, int i) {
        String lastIChars = n.substring(n.length() - i);
        String firstIChars = n.substring(0, n.length() - i);

        return lastIChars + firstIChars;
    }
}
