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

import java.util.ArrayList;

public class Algorithms {

	public static OutputData getOutput(InputData inputdata) {
		// TODO Auto-generated method stub
		int [] Results = new int[inputdata.getTest_Number()];
		
		for(int i=0;i<Results.length;i++){
			Results[i] = getSingleResult(inputdata.getA()[i], inputdata.getB()[i]);
		}
		
		OutputData outputdata = new OutputData(Results);
		return outputdata;
	}

	private static int getSingleResult(int a, int b) {
		// TODO Auto-generated method stub
		int result = 0;
		for(int i=a;i<b+1;i++){
			ArrayList<Integer> number = new ArrayList<Integer>();
			ArrayList<Integer> numbers = new ArrayList<Integer>();
			int temp = i; 
			while(temp/10>0){
				number.add(temp%10);
				temp = temp/10;
			}
			number.add(temp%10);
			
			for(int j=0;j<number.size();j++){
				numbers.clear();
				for(int k=0;k<number.size();k++){
					numbers.add(number.get(k));
				}
				ArrayList<Integer> part = new ArrayList<Integer>();
				for(int k=0;k<j;k++){
					int temp1 = numbers.remove(0);
					part.add(temp1);
				}
				numbers.addAll(part);
				
				int newint = 0;
				for(int k=0;k<numbers.size();k++){
					newint += numbers.get(k)*pow(10,k);
				}
				//System.out.println(i+" "+newint+" "+j);
				if(i<newint && newint<=b){
					System.out.println(i+" "+newint+" "+j);
					result++;
				}
			}
			//System.exit(0);
		}
		return result;
	}

	private static Integer pow(int i, int k) {
		// TODO Auto-generated method stub
		if(k==0){
			return 1;
		}else{
			return pow(i, k-1)*i;
		}
	}


}
