/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}

package R2012;

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

public class RecycledNumbers {

	public static boolean isCycle(int a,int b) {
		String aa=String.valueOf(a);
		StringBuffer ba=new StringBuffer(String.valueOf(b));
		if(aa.length()!=ba.length())
			return false;
		int l=aa.length();
		for(int i=0;i<l;++i)
		{
			if(aa.equals(ba.toString()))
				return true;
			ba.append(ba.charAt(0));
			ba.deleteCharAt(0);
		}
		return false;
	}
	public static boolean sameLen(int a,int b) {
		return String.valueOf(a).length()==String.valueOf(b).length();
	}
	public static void main(String[] args) {
		int T,count,a,b,num;
		try {
			FileWriter out = new FileWriter("d://test//Cs.out");  
			//Scanner in=new Scanner(System.in);
			Scanner in=new Scanner(new File("d://test//Cs.in"));
			T=in.nextInt();
			count=0;
			while((++count)<=T)
			{
				a=in.nextInt();
				b=in.nextInt();
				num=0;
				for(int i=a;i<=b;++i)
					for(int j=i+1;sameLen(i, j)&&j<=b;++j)
						if(isCycle(i, j))
							++num;
				
				out.write("Case #"+count+": "+num+"\r\n"); 
			}
			
			in.close(); 
			out.close();  
		} catch (Exception exc) {
			exc.printStackTrace();
		}
	}

}
