/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;


public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		RecycledNumbers r = new RecycledNumbers();
		r.run("C-small.in", "C-small.out");
	}
	
	public void run(String input, String output) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader(input));
		FileWriter fw = new FileWriter(output);
		long C = 0;
		int N = new Integer(br.readLine());
		for (int cases = 1; cases <= N; cases++) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			long A = new Long(st.nextToken());
			long B = new Long(st.nextToken());
			C = count(A, B);
			fw.write("Case #" + cases + ": " + C + "\n");
		}
		fw.flush();
		fw.close();
	}
	
	public long count(long A, long B) {
		int recycledPairs = 0;
		for (long K = A; K <= B; K++) {
			int n = digits(K);
			int pairs = 0;
			long[] a = new long[n - 1];
			for (int i = 1; i < n; i++) {
				long divisor = (long) Math.pow(10, i);
				long R = (K % divisor) * (long) Math.pow(10, n - i) + (K / divisor);
				if (R > K && R <=B) {
					boolean repeat = false;
					for (int j = 0; j < pairs; j++) {
						if (R == a[j]) {
							repeat = true;
							break;
						}
					}
					if (!repeat) {
						a[pairs] = R;
						pairs++;
						recycledPairs++;
					}
				}
			}
		}
		return recycledPairs;
	}
	
	public int digits(long k) {
		int length = 0;
		for (int i = 0; i < 8; i++) {
			k /= 10;
			length++;
			if (k == 0)
				break;
		}
		return length;
	}
}
