import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 *
 * @author akila
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // TODO code application logic here
        ArrayList<String> testCases = new ArrayList<String>();
        boolean isCaseNo = true;
        int testCount = 0;
        FileReader fr = new FileReader("C-small-attempt0.in");
        BufferedReader br = new BufferedReader(fr);
        String s;

        while ((s = br.readLine()) != null) {
            if (isCaseNo) {
                testCount = Integer.parseInt(s);
                isCaseNo = false;
            } else {
                testCases.add(s);
            }
        }
        fr.close();
        Solve(testCount, testCases);
    }

    public static void Solve(int testCount, ArrayList<String> testCases) throws IOException {


        FileWriter fstream = new FileWriter("out.txt");
        BufferedWriter out = new BufferedWriter(fstream);

        for (int i = 0; i < testCount; i++) {
            int A = 0, B = 0, count = 0;
            String s = testCases.get(i);
            String[] ar = s.split(" ");
            A = Integer.parseInt(ar[0]);
            B = Integer.parseInt(ar[1]);

            for(int j = A; j <= B; j++) {
                ArrayList<NumberPair> nums = new ArrayList<NumberPair>();
                String num = String.valueOf(j);
                for(int k =0; k < num.length(); k++) {
                    String num1 = num.substring(0, k);
                    String num2 = num.substring(k, num.length());

                    String newNum = num2 + num1;
                    int newI = Integer.parseInt(newNum);

                    NumberPair np = new NumberPair(j, newI);
                    if (newI >= A && newI <= B 
                            && newNum.equals(String.valueOf(newI))
                            && !num.equals(newNum)
                            && !nums.contains(np)) {
                        count++;
                        nums.add(np);
                    }                       
                }
            }

            out.write("Case #" + (i + 1) + ": " + count/2 + "\n");
        }
        out.close();
    }
}

class NumberPair {
   int m, n;

    public NumberPair(int m, int n) {
        this.m = m;
        this.n = n;
    }
  
    @Override
    public boolean equals(Object obj) {
        NumberPair np = (NumberPair)obj;
        return (np.m == this.m && np.n == this.n) || (np.m == this.n && np.n == this.m);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 61 * hash + this.m;
        hash = 61 * hash + this.n;
        return hash;
    }

}
