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.io.*;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class GCJ2012QualC {
    static final int MAXB = 2000000;
    int[] minR = new int[MAXB+1];
    int[] count = new int[MAXB+1];

    public void run() throws IOException {
        for (int a = 1; a <= MAXB; a *= 10) {
            for (int x = a; x < 10*a && x <= MAXB; ++x) {
                minR[x] = x;
                int y = x;
                do {
                    y = y % 10 * a + y / 10;
                    if (y / a != 0 && y < minR[x]) {
                        minR[x] = y;
                    }
                }
                while (y != x);
            }
        }
        
        int T = nextInt();
        for (int i = 1; i <= T; ++i) {
            out.println("Case #" + i + ": " + solve());
        }
    }

    private int solve() throws IOException {
        int A = nextInt();
        int B = nextInt();

        Arrays.fill(count, 0, B+1, 0);
        
        for (int i = A; i <= B; ++i) {
            ++count[minR[i]];
        }
        
        int ans = 0;
        
        for (int i = 0; i <= B; ++i) {
            ans += count[i] * (count[i] - 1) / 2;
        }
        
        return ans;
    }

    public static BufferedReader in;
    public static PrintStream out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);

        String className = GCJ2012QualC.class.getSimpleName();
        char lastChar = className.charAt(className.length() - 1);
        System.setIn(new FileInputStream(lastChar + ".in"));
        System.setOut(new PrintStream(lastChar + ".out"));

        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintStream(new BufferedOutputStream(System.out));

        new GCJ2012QualC().run();

        out.close();
    }

    public static StringTokenizer tokenizer;

    public static String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(in.readLine());
        }
        return tokenizer.nextToken();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}
