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

package os;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

public class NewMain1 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int testcase = 0;
        try {
            testcase = Integer.valueOf(br.readLine());
        } catch (IOException ex) {
            Logger.getLogger(NewMain1.class.getName()).log(Level.SEVERE, null, ex);
        }

        for (int z = 1; z <= testcase; z++) {
            String startA = null;
            String startB = null;
            String[] input = new String[2];
            try {
                input = br.readLine().split(" ");
                startA = input[0];
                startB = input[1];
            } catch (IOException e) {
                System.out.println("Error!");
                System.exit(1);
            }
            int countrecycle = 0;
            for (int A = Integer.valueOf(startA); A <= Integer.valueOf(startB); A++) {
                for (int B = Integer.valueOf(startB); B > A; B--) {

                    String num1 = String.valueOf(A);
                    String num2 = String.valueOf(B);
                    for (int i = 1; i < num1.length(); i++) {
                        String temp = "";
                        int count = i;
                        while (count != 0) {

                            temp += num1.charAt(num1.length() - count);
                            count--;
                        }
                        for (int j = 0; j < num1.length() - i; j++) {
                            temp += num1.charAt(j);
                        }
                        if (temp.equals(num2)) {
                            countrecycle++;
                            break;
                        }
                    }

                }
            }
            System.out.println("Case #"+z+": " + countrecycle);
        }
    }
}
