import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}

/*
ID: codeKNIGHT
LANG: JAVA
TASK: 
*/
import java.util.*;
import java.math.*;
import java.io.*;
class recyledNumbers
{
    public static void main(String args[])throws IOException
    {
        //Scanner in=new Scanner(System.in);
        Scanner in=new Scanner(new FileReader("C:\\Users\\Lokesh\\Desktop\\C-large.in"));
        //PrintWriter out=new PrintWriter(System.out);
        //BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\Lokesh\\Desktop\\input.in"));
        PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("E:\\programss\\GCJ\\output.txt")));
        int t=in.nextInt(),test,i,a,b,j;
        String s,s1,s2;
        for(test=1;test<=t;test++)
        {
            a=in.nextInt();
            b=in.nextInt();
            int c=0,k;
            
            for(i=a;i<=b;i++)
            {
                s=Integer.toString(i);
                int max=s.charAt(0);
                boolean stat=false;
                for(j=1;j<s.length();j++)
                {
                    if(s.charAt(j)>=max)
                    {
                        s1=s.substring(j,s.length());
                        s2=s.substring(0,j);
                        
                        k=Integer.parseInt(s1+s2);
                        if(k>i&&k<=b&&!stat)
                        {
                            c++;
                            
                        }
                        if(s1.equals(s2))
                        stat=true;
                    }
                }
                
            }
            out.println("Case #"+test+": "+c);
        }
        out.flush();
        System.exit(0);
    } 
}
