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.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class ProblemC {
	public static void main(String[] args) throws NumberFormatException, IOException{

		BufferedReader reader=new BufferedReader(new FileReader(new File(args[0])));

		int numTestCases=Integer.parseInt(reader.readLine());

		String[] split;

		for (int testCase=0; testCase<numTestCases; testCase++){
			split=reader.readLine().split("\\s+");
			
			int a=Integer.parseInt(split[0]);
			int b=Integer.parseInt(split[1]);
			
			String stra=String.valueOf(a);
			
			String curr;
			int currVal;
			
			int len=stra.length();
			
			Set<String> iCanHasPair=new HashSet<String>();
			
			int result=0;
			
			for (int i=a; i<=b; i++){
				curr=String.valueOf(i);
								
				boolean inRange;
								
				for (int k=1; k<len; k++){
					currVal=0;
					inRange=true;
					
					for (int j=0; j<len; j++){
						currVal+=((int)Math.pow(10, len-j-1))*(curr.charAt((j+k)%len)-'0');
						
						if (currVal>b){
							inRange=false;
							break;
						}
					}
					
					if (currVal<a)
						continue;
					
					if (!inRange)
						continue;
					
					
					if (i!=currVal){
						String key=i<currVal?i+":"+currVal:currVal+":"+i;
					
						if (!iCanHasPair.contains(key)){
							iCanHasPair.add(key);
							result++;
						}
					}

				}
				
			}
			
			
			System.out.println("Case #"+(testCase+1)+": "+result);
		}		
	}
}
