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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
package taskc;

import java.io.FileNotFoundException;
import java.util.*;
import java.io.File;
import java.io.PrintWriter;

public class TaskC {
    
    private long[] tenPowers = new long[10];
    private long[]prevPairs = new long[10];
    private void prepareTenPowers(){
        tenPowers[0] = 1;
        for(int i = 1;i<10;i++){
            tenPowers[i]=tenPowers[i-1]*10;
        }
    }
    
    private void solve(Scanner in, PrintWriter out, int caseNum){
        long res = 0;
        long A = in.nextInt();
        int B = in.nextInt();
        for(long t = A;t<=B;t++){
            long d = t;
            int aPow = 0;
            while(d>0){
                aPow++;
                d = d/10;
            }
            long pow = 10;
            d = t/10;
            int k = 1;
            int pairsCnt = 0;
            
            while(d>0){
                long rest = t%pow;
                if(rest!=0){
                    long pair = rest*tenPowers[aPow-k]+ d;
                    if((pair>t)&&(pair<=B)){
                        boolean ok = true;
                        check:
                        for(int i = 0;i<pairsCnt;i++){
                            if(prevPairs[i]==pair){
                                ok = false;
                                break check;
                            }
                        }
                        if(ok){
                          //System.out.println(t + " " + pair);
                            res++;
                            prevPairs[pairsCnt] = pair;
                            pairsCnt++;
                        }
                    }
                }
                k++;
                pow*=10;
                d /=10;
            }
        }
        out.format("Case #%d: %s\n", caseNum, res);
    }

    public TaskC(){
        prepareTenPowers();
        try{
            Scanner in = new Scanner(new File("C-large.in"));
            int T = in.nextInt();
            PrintWriter out = new PrintWriter("Clarge.out");
            for(int i = 0;i<T;i++){
                solve(in,out,i+1);
            }
            out.close();
        } catch (FileNotFoundException e){
            System.out.println("File not found");
        }
        
    }
    public static void main(String[] args) {
        TaskC instance = new TaskC();
    }
}
