import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;


public class CodeJam2012C
{
	public static void main(String [] args) throws FileNotFoundException
	{
		new CodeJam2012C().go();
	}
	
	public void go() throws FileNotFoundException
	{
		PrintWriter writer = new PrintWriter(new File("output.txt"));
		Scanner in = new Scanner(new File("C-large.in"));
//		Scanner in = new Scanner(System.in);
		int iterations = in.nextInt();
		for (int i = 0; i < iterations; i++)
		{
			int A = in.nextInt();
			int B = in.nextInt();
			int counter = 0;
			for (int j = 0; j < (B - A); j++)
			{
				String s = (j + A) + "";
				for (int k = 0; k < s.length() - 1; k++)
				{
					s = s.substring(1) + s.charAt(0);
					int temp = Integer.parseInt(s);
					if (temp <= B && (j + A) < temp)
						counter++;
				}
			}
//			System.out.println("Case #" + (i + 1) + ": " + counter);
			writer.write("Case #" + (i + 1) + ": " + counter + "\n");
		}
		writer.flush();
		writer.close();
	}
}
