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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

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


public class rec2 {
	public static void main(String args[]) throws Exception{
		FileInputStream fs = new FileInputStream("input2.txt");
	    DataInputStream in = new DataInputStream(fs);
	    BufferedReader br=new BufferedReader(new InputStreamReader(in));
	    FileWriter fstream = new FileWriter("output3.txt");
		BufferedWriter out = new BufferedWriter(fstream);
		int T=Integer.parseInt(br.readLine());
	    for(int i=0;i<T;i++){
	    	int temp=0;
	    	long[] found=new long[10000000];
	    	int count=0;
	    	String str=br.readLine();
	    	String str1[]=str.split(" ");
	    	int nod=str1[1].length();
	    	int A=Integer.parseInt(str1[0]);
	    	int B=Integer.parseInt(str1[1]);
	    	for(int x=A;x<=B;x++){
	    		if(found[x]!=1){
	    			int t=1;
	    			int a=x;
	    			found[a]=1;
	    			int n1=nod-1;
	    			for(int k=0;k<n1;k++){
	    				int b=((a%10)*((int)Math.pow(10,n1)))+(a/10);
	    				if(b!=x && found[b]!=1 && b<=B && A<=b){
	    					t++;
	    					found[b]=1;
	    				}
	    				a=b;	    			
	    			}
	    			count=count+((t*(t-1))/2);
	    		}
	    	}
	    	out.write("Case #"+(i+1)+": "+count);
			out.newLine();
	    }
	    out.close();
		br.close();
	   }
}