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

import java.util.HashSet;

/**
 *
 * @author vandit
 */
public class RecycleNumbers {

    private HashSet<String> numbers = new HashSet<String>();
    private HashSet<String> initialTempNumbers = new HashSet<String>();
    private HashSet<String> finalTempNumbers = new HashSet<String>();

    HashSet<Pair> numberPairs = new HashSet<Pair>();


    private void findRecycledNumbers(int start, int end, int places) {


        for (int i = start; i <= end; i++) {
            String initialNumber = Integer.toString(i);
            //if (!(numbers.contains(initialNumber) || finalTempNumbers.contains(initialNumber))) {

                StringBuffer tempNumber = new StringBuffer(initialNumber);
                int len = tempNumber.length();
                int startIndexToMove = len - places;
                String tempString = tempNumber.substring(startIndexToMove);
                if ((places == 1 && tempString.equals("0")) || tempString.charAt(0) == '0') {
                    continue;
                }
                tempNumber.delete(startIndexToMove, len);
                String finalTempNumber = tempString + tempNumber.toString();

                if (! (finalTempNumber.equals(initialNumber) || Integer.parseInt(finalTempNumber) > end || Integer.parseInt(finalTempNumber) < Integer.parseInt(initialNumber))) {
                    numbers.add(initialNumber);
                    finalTempNumbers.add(finalTempNumber);
                    Pair pair = new Pair(finalTempNumber,initialNumber);
                    numberPairs.add(pair);
                }
            }

        

    }

    public HashSet<Pair> findAllRecycledNumbers(int start, int end) {
        int length = Integer.toString(start).length();
        for (int i = 1; i < length; i++) {
            findRecycledNumbers(start, end, i);
        }
        return numberPairs;
    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.*;

/**
 *
 * @author virginia
 *
 */
public class RecycledNumbers {
	public static int countn(int v)
	{
		int count=0;
		while (v> 0 && count<10 )
			{
				   int r = v % 10;
					count++;
				   v = v / 10;
	        }
	        return count;
		}
 public static void main(String[] args) {

 try {
   BufferedReader br = new BufferedReader(new FileReader("C-small-attempt1.in"));
   BufferedWriter output=new BufferedWriter(new FileWriter("Output.txt"));
  PrintWriter pw = new PrintWriter(output);

int n = Integer.parseInt(br.readLine());
 int[][] result = new int[n][2];

 String line;
 int a= 0;
 while ((line = br.readLine()) != null) {
  String[] tokens = line.split("\\s");

  for (int j = 0; j <2; j++) {
   result[a][j] = Integer.parseInt(tokens[j]);
  }

  a++;
 }
    int index = 0;

   for(int i =0; i < n; i++)
   {
	    int found=0;
								index++;
							   int A=result[i][0];
							   int B=result[i][1];
							   for(int j=A;j<=B;j++)
							   {
											  int cnt=0;
											  int num=j;
											  int rev=0;
												while (num> 0 && cnt<10 )
												{
													   int r = num % 10;
														cnt++;
													   num = num / 10;

												}
												int num1=j;
												int num2=j;
												int p=cnt-1;
												int r=0;
												do
												{
													cnt--;
													int s=(num1)%10;
													num2=num2/10;
													num1=(int)(s*Math.pow(10,(p)))+(num2);

													num2=num1;

													if(RecycledNumbers.countn(j)==RecycledNumbers.countn(num1))
													{
													if((A<=j)&&(j<num1)&&(num1<=B))
													{


														 found++;
												}}
												 }while(cnt>0);
								  }
   pw.print("Case #" + index + ": ");
   pw.println(found);
   System.out.print("Case #" + index + ": ");
   System.out.println(found);
   }
   output.close();
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}
