import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}

//RECYCLED NUMBERS

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;

//Importing classes / interface from java.io pacckage to work with files

public class RecycledNumbers
{
	static boolean checkForNewM(long temp , long [] m , long totalMForThisN)
	{
		for(int i = 0 ; i < totalMForThisN ; i++)
		{
			if(temp == m[i])
			{
				return false;
			}
		}
		
		return true;
	}
	
	public static void main(String[] args)
	{
		try
		{
			// Open the input file
			FileInputStream fistream = new FileInputStream("C-large.in");
			
			// Get the object of DataInputStream
			DataInputStream in = new DataInputStream(fistream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String strLine;
			
			//Create output file
			File file = new File("output.out");
			boolean exist = file.createNewFile();
			
			if (!exist)
			{
				System.out.println("File already exists.");
				System.exit(0);
			}
			
			FileWriter fostream = new FileWriter("output.out");
			BufferedWriter out = new BufferedWriter(fostream);
			
			int counterCases = 0;		//Counter purpose
			
			//Read File Line By Line
			int totalNumberOfCases = 0;
			while ((strLine = br.readLine()) != null)
			{
				if(counterCases == 0)
				{
					//Ignore the first Line for Conversion
					totalNumberOfCases = Integer.parseInt(strLine);
					counterCases++;
					continue;
				}
				
				String[] results = strLine.split(" ");
				
				long A = Long.parseLong(results[0]);
				long B = Long.parseLong(results[1]);
				
				int counter = 0;
				
				for(long n = A ; n < B ; n++)
				{			
					String nTemp = "" + n;
					String mTemp;
					
					int totalMForThisN = 0;
					long [] m = new long [nTemp.length() - 1];
					
					for(int i= (nTemp.length() - 1) ; i >= 0 ; i--)
					{
						mTemp = nTemp.substring(i) + nTemp.substring(0,i);
						
						if(mTemp.startsWith("0"))
						{
							continue;
						}
						else
						{
							long temp = Long.parseLong(mTemp);
							
							if(temp > n && temp <= B)
							{
								if(checkForNewM(temp, m, totalMForThisN))
								{
									m[totalMForThisN] = temp;
									totalMForThisN++;
									counter++;
								}
							}
						}
					}
				}
				// Print the content in the output file
				out.write("Case #" + counterCases + ": " + counter);
				
				if(counterCases < totalNumberOfCases)
				{
					out.write("\n");
				}
				counterCases++;
			}
			//Close the input stream
			in.close();

			//Close the output Stream
			out.close();
		}
		
		catch(Exception e)
		{
			//Catch exception if any
			System.err.println("Error: " + e.getMessage() + " : " + e);
		}
	}
}