import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

//	static int MAX = 10000;
	static int MAX = 2000000;
	static Object[] All = new Object[MAX+1];
	
	static int size( int x ) {
		if(x>999999) return 7;
		if(x>99999)  return 6;
		if(x>9999)   return 5;
		if(x>999)    return 4;
		if(x>99)     return 3;
		if(x>9)      return 2;
		return 1;
	}
	static int[] rotate( int value ) {
		List<Integer> result = new ArrayList<Integer>();
		int[] V = new int[8];
		int s = size(value);
		int x = value;
		
		for(int i=s-1;i>=0;i--) {
			V[i] = x%10;
			x /=10;
		}
		int rot;
		for(int i=1; i<s; i++) {
			if(V[i]!=0){
				rot=0;
				for(int j=0,ii=i;j<s; j++,ii=(ii+1)%s){
					rot=rot*10+V[ii];
				}
				if(rot>value && !result.contains(rot))
					result.add(rot);
			}
		}
		if( result.isEmpty() )
			return null;
		int[] r = new int[result.size()];
		for(int i=0; i<r.length; i++)
			r[i]=result.get(i);
		return r;
	}
	
	static void precalculate() {
		for(int i=1; i<=MAX; i++){
			All[i] = rotate(i);
		}
	}
	static int solve( Scanner in ) {
		int A, B, sol=0;
		
		A = in.nextInt();
		B = in.nextInt();

		for( int i=A; i<=B; i++) {
//			List<Integer> result = rotate(i);
			if( All[i]!=null ) {
				for(int value: (int[])All[i] ) {
					if( value <= B )
						sol++;
				}
			}
		}

		return sol;
	}
	
	public static void main ( String args[] ) {
		int T; 
		Scanner in = new Scanner(System.in);
		T = in.nextInt();
		int cnt=0;
		int sol;
		precalculate();
		for( cnt=1; cnt<=T; cnt++ ) {
			sol = solve( in );
			System.out.printf("Case #%d: %d\n", cnt, sol);
		}

	}
}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;


public class question3CodeJam {
	
	public int MAX=0;
	public int MIN=0;
	public int COUNTERVALS = 0;
	public int findInversions(){
		
		for(int i=MIN;i<=MAX;i++){
			if(i<10){
				continue;
			}
			String finalizeVals = i+"";
			String tmpString1 = i+"";
			String tmpString2 = "";
			//first string
			HashMap<Integer, Integer> valFound = new HashMap<Integer, Integer>();
			for(int j=0;j<finalizeVals.length();j++){
				String part1 = tmpString1.substring(j+1, tmpString1.length());
				String part2 = tmpString1.substring(0,j+1);
				tmpString2 = part1 + part2;
				int val1;
				try{
					val1 = Integer.parseInt(tmpString1);
				} catch (NumberFormatException ex){
					val1 = 0;
				}
				int val2;
				try{
					val2 = Integer.parseInt(tmpString2);
				} catch (NumberFormatException ex){
					val2 = 0;
				}
				//int val1 = Integer.parseInt(tmpString1);
				//int val2 = Integer.parseInt(tmpString2);
				if ((MIN <= val1) && (val1 < val2) && (val2 <= MAX)) {
					if(valFound.containsKey(val2)){
						System.out.println("(" + val1 + " , " + val2 +")");
					} else {
						valFound.put(val2, 1);
						COUNTERVALS++;
						//System.out.println("(" + val1 + " , " + val2 +")");
					}
					
					//System.out.println("(" + val1 + " , " + val2 +")");
				}
			}
			//take good care of 0s for sure
		}
		return COUNTERVALS;
	}
	public static void main(String[] args){
		
	    try{
		    File file = new File(args[0]);
		    
		    FileWriter fstream = new FileWriter(args[1]);
		    BufferedWriter out = new BufferedWriter(fstream);
		    
		    BufferedReader in = new BufferedReader(new FileReader(file));
		    
		    String line = in.readLine();
		    //here line is the number of rounds
		    int counter=0;
		    int testCase = Integer.parseInt(line);
		    
		    while (counter<testCase) {
		    	question3CodeJam tmp = new question3CodeJam();
		    	String inline = in.readLine();
		    	String[] val = inline.split(" ");
		    	
		    	//initializing
		    	tmp.MIN = Integer.parseInt(val[0]);
		    	tmp.MAX = Integer.parseInt(val[1]);
		    	
		    	++counter;
		    	//System.out.println("Case #" + counter + ": " + tmp.computeAtLeastP());
		    	//out.write(inline);
		    	out.write("Case #" + counter + ": " + tmp.findInversions());
		    	out.write("\n");
	    	}
		    out.close();
		    in.close();
	    }
	    catch(IOException e){
	    	
	    	System.out.println("IO Error");
	    }
	    catch (ArrayIndexOutOfBoundsException e){
	    	System.out.println("Array Error");
	    	e.printStackTrace();
	    }
		
	}
}
