import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

public class Main {
	public static void main(String[] args) throws java.io.FileNotFoundException,java.io.IOException{
		java.io.BufferedReader bRead=new java.io.BufferedReader(new java.io.FileReader("F:\\C-small-attempt0.in"));
		java.io.BufferedWriter bWrite=new java.io.BufferedWriter(new java.io.FileWriter("F:\\C-small-attempt0.out"));
		java.util.HashMap<Integer,Integer> mVals=new java.util.HashMap<Integer,Integer>();
		StringBuffer output=new StringBuffer();		
		int noCases=Integer.parseInt(bRead.readLine());
		for(int i=0;i<noCases;i++){	
			String[] curLine=bRead.readLine().split(" ");
			int A=Integer.parseInt(curLine[0]),B=Integer.parseInt(curLine[1]),dig=curLine[0].length(),n=A,noPairs=0;
			while(n<B){
				int m;mVals.clear();
				for(int j=1;j<dig;j++){
					m=((n%(int)Math.pow(10,dig-j))*(int)Math.pow(10,j))+n/((int)Math.pow(10,dig-j));
					if(m>n&&m<=B&&!mVals.containsKey(m)){noPairs++;mVals.put(m,0);}
				}
				n++;
			}
			output.append("Case #"+(i+1)+": "+noPairs+"\n");
		}
		bWrite.write(output.toString());
		bWrite.close();bRead.close();
	}
}
