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

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

public class CodeJam13 {
	char map[];

	public static void main(String[] args) {
		Scanner fileIn = null;
		FileWriter fileOut = null;

		try {
			fileIn = new Scanner(new File("input.txt"));
			fileOut = new FileWriter(new File("output.in"));
			int noOfTestCases = Integer.parseInt(fileIn.nextLine());

			int testCase = 0;
			while (fileIn.hasNextLine()) {
				testCase++;
				int count=0;
				
				String sa = fileIn.next();
				int len = sa.length();
				int factor = (int)Math.pow(10,len-1);
				int a = Integer.parseInt(sa);
				int a1=a;
				int b = fileIn.nextInt();
				fileIn.nextLine();
				
				while(a1<=b){
					HashSet set = new HashSet();
					for(int i=0;i<len-1;i++){						
						int newA = (a%10)*factor + a/10;					
						set.add(a1);						
						if(newA<factor){
							
						}
						else if(newA>=a1 && newA<=b){
							if(set.add(newA)){
								count++;
							}
						}						
						a=newA;					
					}
					//System.out.println(a1 + "   " + count);
					a=++a1;
				}
							
				fileOut.write("Case #" + testCase + ": " + count
						+ "\n");
			}
			fileIn.close();
			fileOut.close();
		} catch (IOException ex) {
			System.out.println(ex.getMessage());
		}
	}

}
