/*
 * 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.InputStreamReader;
import java.util.HashSet;
import java.util.Scanner;

public class Recycled_Num {

	public static void main(String[] args) {
		//long currentTime = System.currentTimeMillis();
		Scanner input_file = new Scanner(new InputStreamReader(System.in));
		String input_line = null;
		String[] numb_arr;
		int Case_Count = 0;
		int st_num = 0;
		int end_num = 0;
		int pair_count = 0;
		int digitCount = 0;
		StringBuilder recycle_number = new StringBuilder();
		int newNumber = 0;
		String newNumberString;
		HashSet<String> recycle_numbers = new HashSet<String>();
		while (input_file.hasNextLine()) {
			input_line = input_file.nextLine();
			numb_arr = input_line.split(" ");
			if(numb_arr != null && numb_arr.length == 1) {
				/*numberOfTestCases = Integer.parseInt(numb_arr[0]);*/
			} else if (numb_arr != null && numb_arr.length == 2) {
				digitCount = numb_arr[0].length();
				st_num = Integer.parseInt(numb_arr[0]);
				end_num = Integer.parseInt(numb_arr[1]);
				while(st_num <= end_num) {
					newNumberString = "" + st_num;
					for(int i = 1; i < digitCount; i++) {
						recycle_number = recycle_number.append(newNumberString.substring(i) + newNumberString.substring(0, i));
						newNumber = Integer.parseInt(recycle_number.toString());
						if(newNumber > st_num && newNumber <= end_num) {
							recycle_numbers.add(recycle_number.toString());
						}
						recycle_number.delete(0, digitCount);
					}
					pair_count = pair_count + recycle_numbers.size();
					st_num++;
					recycle_numbers.clear();
				}
				System.out.println("Case #" + Case_Count + ": " + pair_count);
			}
			Case_Count++;
			pair_count = 0;
			st_num = 0;
			end_num = 0;
			digitCount = 0;
			newNumber = 0;
			recycle_number.delete(0, digitCount);
		}
		//System.out.println(System.currentTimeMillis() - currentTime);
	}
}
