import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

package problemC;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class RecycledNumbers {
	
	private static BufferedWriter out = null;
	private static int numberOfTestCases;
	static String[] testCases;
	
	private static void loadData()
	{
		BufferedReader in = null;
		try {
			in = new BufferedReader(new FileReader("C-small-attempt0.in"));
//			in = new BufferedReader(new FileReader("inputC.small"));
//			in = new BufferedReader(new FileReader("C-large.in"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		try {
			numberOfTestCases = Integer.parseInt(in.readLine());
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

//		System.out.println(numberOfTestCases);

		testCases = new String[numberOfTestCases];
		String testCase = null;

		for (int i=0; i<numberOfTestCases; i++)
		{
			//tasks = new LinkedList<Task>();
			try {
//				in.readLine();
				testCases[i] = in.readLine();
//				System.out.println(testCases[i]);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	private static boolean isRP(String a, String b)
	{
		String c = a.concat(a);
		if (c.contains(b))
			return true;
		return false;
	}
	
	public static void main(String argv[])
	{
		loadData();
		
		try {
			out = new BufferedWriter(new FileWriter("outputC.small"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		int pairC = 0;
		for (int i=0; i<numberOfTestCases; i++)
		{
			String[] testCaseItems;
			testCaseItems = testCases[i].split(" ");
			int a = Integer.parseInt(testCaseItems[0]);
			int b = Integer.parseInt(testCaseItems[1]);
			
			for (int j=a; j<b; j++)
			{
				for (int k=j+1; k<=b; k++)
				{
					if (isRP(String.valueOf(j), String.valueOf(k)))
						pairC++;
				}
			}
			
			try {
				out.write("Case #"+(i+1)+": " + pairC);
				out.newLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			pairC = 0;
		}
		
		try {
			out.flush();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
