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);
	}
}

import java.io.File;
import java.lang.StringBuilder;
import java.util.Scanner;
import java.io.FileWriter;

public class RN {
	
	public static void main(String[] args) throws Exception{
		File input = new File("C-small-attempt1.in");
		File output = new File("output.out");
		FileWriter fw = new FileWriter(output);
		Scanner s = new Scanner(input);
		
		int numloops = s.nextInt();
		StringBuilder sb = new StringBuilder();
		
		for(int n=0; n<numloops; n++){
			sb.append("Case #" + (n+1) + ": ");
			
			int low = s.nextInt();
			int hi = s.nextInt();
			int numrepeats = 0;
			
			for(int i=low; i<hi; i++){
				String strnum = "" + i;
				//System.out.println(strnum);
				
				for(int j=1; j<strnum.length(); j++){
					String rotstr = strnum.substring(j) + strnum.substring(0,j);
					//System.out.println(rotstr);
					int rotval = Integer.parseInt(rotstr);
					rotstr = "" + rotval;
					
					if(rotval > i && rotval <= hi ){//&& rotstr.length() == strnum.length()){
						numrepeats++;
						//System.out.println(strnum + " " + rotstr);
					}
					
					if(rotval == i)
						;//break; //already had a repeating number
				}
			}
			sb.append(numrepeats + "\n");
			//fw.append(numrepeats + "\n");
		}
		fw.write(sb.toString());
		fw.close();
	}
}
