import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class A {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader in = new BufferedReader(new FileReader("C-small-attempt0.in"));
  		FileWriter fw = new FileWriter("output.out");
  		/*BufferedReader in = new BufferedReader(new FileReader("A-large.in"));
  		FileWriter fw = new FileWriter("A-large.out");*/
  		int N = new Integer(in.readLine());
  		String[] output = new String[N];
  		int[] trueCount = new int[N];
  		for (int cases = 0; cases < N; cases++) {
  			int CaseNo = cases+1;
  			output[cases] = "";
  			StringTokenizer G = new StringTokenizer(in.readLine());
  			int W = G.countTokens();
  			int[] a = new int[2];
  			String[] b = new String[W];
  			for (int j = 0; j < a.length; j++) {
  				a[j] = new Integer(G.nextToken());
  			}
  			int counter = 1;
  			int A =a[0];
  			int B =a[1];
  			int C = a[0];
  			System.out.println(A + "  x  " +B);
  			
  			int lengthA = Integer.toString(A).length();
  			if (lengthA == 1){
  				trueCount[cases] = 0;
  			}
  			else{
	  			int range = B - A + 1;
	  			int[] rangeA = new int[range];
	  			rangeA[0] = A;
	  			while (A<B){
	  				A = A+1;
	  				rangeA[counter] = A;
	  				counter=counter+1;
	  			}
	  			for (int ii=0;ii<range;ii++){
	  				int currentN = rangeA[ii];
	  				int currentM = rangeA[ii];
	  				int length = Integer.toString(rangeA[ii]).length();
	  				String curM = Integer.toString(currentM);
	  				for (int jj=0; jj<length;jj++){  					
	  					curM = curM.charAt(length-1) + curM.substring(0, length-1);
	  					currentM = Integer.parseInt(curM);	  					
	  					if (currentM <= B && currentM > currentN && currentM >= C){
	  						trueCount[cases]+=1;
	  					}
	  				}
	  				
	  			}  	
  			}
  			fw.write("Case #"+CaseNo+": "+ trueCount[cases]+ "\n");  			
  			
  		}
  		fw.flush();
  		fw.close();
	}
}
