/*
 * 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 codejam;

import java.io.File;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Scanner;


public class QualificationC {
	public static long recycled(long nr1,long b){
		long count=0;
		String n1=String.valueOf(nr1);
		String n2=n1;
		HashMap<String,Boolean> gen=new HashMap<String,Boolean>();
		for(int i=0;i<n2.length();i++){
			n2=n2.substring(1,n2.length())+n2.substring(0,1);
			if(gen.containsKey(n2))continue;
			else gen.put(n2,Boolean.TRUE);
			long nr2=Long.parseLong(n2);
			if(String.valueOf(nr2).length()!=n1.length())continue;
			if(nr2>nr1&&nr2<=b){
				count++;
			}
		}
		return count;
	}
	public static void main(String[] args){
		try{
			Scanner sc=new Scanner(new File("C.in"));
			PrintStream ps=new PrintStream("C.out");
			int n=sc.nextInt();
			long a,b;
			for(int i=0;i<n;i++){
				long count=0;
				a=sc.nextLong();
				b=sc.nextLong();
				for(long nr1=a;nr1<b;nr1++)
					count+=recycled(nr1,b);
				ps.println("Case #"+(i+1)+": "+count);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
