package codejam;

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

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}


public class RecycleNumber {
	
	int count=0;
	public RecycleNumber(int A,int B){
		for(int n=A;n<B-1;n++){
			for(int m=n+1;m<=B;m++){
				if(isRecycledPair(n,m)){
					count++;
				}
			}
		}
	}
	
	public int getCount() {
		return count;
	}


	boolean isRecycledPair(int a,int b){
		String sA=a+"";
		String sB=b+"";
		//start from 
		int countB=sB.length();
		int countA=sA.length();
		if(countA!=countB)return false;
		for(int i=0;i<sA.length();i++){
			if(sA.charAt(i)==sB.charAt(0)){
				if(sA.charAt(i)=='0') continue;
				if(compare(sA,i,sB))
					return true;
			}
		}

		return false;
	}
	private boolean compare(String sA, int i, String sB) {
		// TODO Auto-generated method stub
		int count=0;
		int length=sB.length();
		for(int j=i,k=0;count<length;k++,count++,j=(j+1)%length){
			if(sA.charAt(j)!=sB.charAt(k)){
				return false;
			}
		}
		return true;
	}

}
