import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

	

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.math.BigInteger;

public class C {

    private static char[] alph;
    private static String  fileIN = "./A.in"; //archivo de entrada (en el dir local del programita)
    private static String  fileOUT = "./out.txt"; //salida

    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File(fileIN));
        PrintWriter out = new PrintWriter(new File(fileOUT));
        int T = in.nextInt();
        for (int i = 0; i < T; i++) {
            String s = "Case #" + (i + 1) + ": " + new C().solve(in);
            out.println(s);
            System.out.println(s);
         }
        
        
        out.close();
    	//getCombinaciones(1234);
    }
/**
* Retorna la solucion a un caso
**/
    private String solve(Scanner in) {
    	int min, max = 0;
    	min= in.nextInt();
    	max= in.nextInt();
    	int tot = 0;
    	int tot_[] = new int[6];
    	int prov = 0;
    
    	for(int i = min; i< max; i++){
    		for(Integer j: getCombinaciones(i)){
    			//System.out.println(j);
    			if(j>i)
    			if(isValid(j, min, max)) prov++;
    		}
    		tot_[prov]++;
    		tot+= prov;
    		prov =0;
    	}
    /*	for(int i = 0; i < tot_.length; i++){
    		tot-= 
    	}*/
    	
    	return String.valueOf(tot);
    }
    
	private boolean isValid(Integer j, int min, int max) {
		
		return j<=max && j>=min;
	}
	private static List<Integer> getCombinaciones(int i) {
		ArrayList<Integer> l = new ArrayList<Integer>();
		
		String is = String.valueOf(i); 
		String aux = String.valueOf(i);
		if(symetric(is)) return l;
		do{
			aux = aux.charAt(aux.length()-1)+ aux.substring(0, aux.length()-1);
		
			if(aux.charAt(0)!='0')
			l.add(Integer.valueOf(aux));
		}
		while(!is.equals(aux));
		l.remove(l.size()-1);
		
		return l;
	}
	private static boolean symetric(String is) {
		if(is.length() % 2 ==1) return false;
		else return is.substring(0, is.length()/2).equals(is.substring(is.length()/2 + 1, is.length()));
		
	}
	    
    
   
  }

