/*
 * 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);
        
    }
    }
}

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Problem3 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		File file = new File("small-input.in");
		File outputFile = new File("output.txt");
		try {
			FileWriter writer = new FileWriter(outputFile);
			BufferedWriter out = new BufferedWriter(writer);
			Scanner scanner = new Scanner(file);
			int count = 0;
			
			while (scanner.hasNextLine()) {
				count = count + 1;
				String line = scanner.nextLine();

				if (count >= 2) {
					int finalCount = 0;
					System.out.println(line);
					String[] stringArr = line.split(" ");
					int num1 = Integer.parseInt(stringArr[0]);
					int num2 = Integer.parseInt(stringArr[1]);
					int tempnum1 = num1;
					//System.out.println("number1 is " + num1);
					//System.out.println("number2 is " + num2);
					for (; tempnum1 <= num2; tempnum1++) {
						String str = String.valueOf(tempnum1);
						ArrayList usedList = new ArrayList();
						for (int j = 1; j < str.length(); j++) {
							String str1 = str.substring(str.length() - j, str
									.length());
							String str2 = str.substring(0, str.length() - j);
							String newStr = str1 + str2;
							int newIntVal = Integer.parseInt(newStr);
							
							if ((num1 <= newIntVal) && ((num2 >= newIntVal))) {
								if(newIntVal>tempnum1){
									if(!usedList.contains(newIntVal)){
									System.out.println("tempNum1 is "+tempnum1);
									System.out.println("newIntVal== "+newIntVal);
									usedList.add(newIntVal);
								finalCount = finalCount+1;
								System.out.println("-------------------------------------------------------------");
								//System.out.println("finalCount is "+finalCount);
									}
								}
							}
						}

					}
                  
					out.write("Case #" + (count - 1) + ": "+finalCount);
					out.newLine();

				}

			}
			out.close();
			writer.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
