import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

import java.io.*;

public class ProCOpt
{
    public static void main(String args[])
    {
        try
        {
            BufferedReader br = new BufferedReader(new FileReader("E:\\test.txt"));
            int n;
            n= Integer.parseInt(br.readLine());
            
            int casen=0,i,j;
            int a,b,count;
            
            String temp,t,u;
            String outp;
            outp="";
            
            String spl[];
            String memory,fp,lp;
            while( casen < n )
            {
                temp = br.readLine();
                outp += "Case #"+(casen+1)+": ";
                
                spl = temp.split(" ");
                a = Integer.parseInt(spl[0]);
                b = Integer.parseInt(spl[1]);
                
                count = 0;
                memory = "";
                
                for(i=a;i<=b; i++)
                {
                	t = i+"";
                	                	
                	for(j=1;j<t.length();j++)
                	{
                		u= t.substring(j);
                		u+= t.substring(0,j);
                		//System.out.println(u);
                		if( !u.startsWith("0") && Integer.parseInt(u) < i && Integer.parseInt(u)<= b && Integer.parseInt(u) >= a)
                		{
                			if( t.length() % 2 == 0 )
                			{
                				fp= t.substring(0,t.length()/2);
                				lp = t.substring(t.length()/2);
                				if( fp.equals(lp) )
                				{
                					if(!memory.contains(Integer.parseInt(u)+" "+i))
                					{
                						count++;
                						memory += Integer.parseInt(u) + " " + i+"\n";
                					}
                				}
                				else
                				{
                					count++;
                				}
                			}
                			else
                			{
                				count++;
                			}
                			/*if( memory.contains(Integer.parseInt(u)+" "+i) )
                				System.out.println(Integer.parseInt(u)+"  "+i);
                			else
                			{
                				count++;
                				memory += Integer.parseInt(u) + " " + i+"\n";
                			}*/
                		}
                	}                	
                }
                outp += count;                
                if( casen != n-1 )
                    outp += "\n";
                casen++;
            }
            System.out.println(outp);

            BufferedWriter bw = new BufferedWriter( new FileWriter("E:\\result.txt"));
            bw.write(outp);
            bw.close();
            
            br.close();
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
    }
}
