/*
 * 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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;


public class recycle {
	public static void main(String[] args) {
		int lines;
		String input;
		StringTokenizer strk;
		int start=1111;
		int end=2222;
		int count;
		
		try {
			BufferedReader inputStream = new BufferedReader(new FileReader("C-large.in"));
			BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt"));
			
			lines = Integer.parseInt(inputStream.readLine());
			for(int line=0; line< lines; line++){
				count=0;
				input = inputStream.readLine();
				strk = new StringTokenizer(input," ");
				start = Integer.parseInt(strk.nextToken());
				end = Integer.parseInt(strk.nextToken());
				
				for(int j=start; j<=end;j++){
					for(int k=j; k<=end;k++){
						if(isRecycled(j+"",k+"")){
							count++;
						}
					}
				}
				
				if(line!=lines-1)
					writer.write("Case #" + (line+1) + ": " + count+"\r\n");
				else
					writer.write("Case #" + (line+1) + ": " + count);
				
			}
			writer.close();
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	static boolean isRecycled(String x, String y){
		int len  = x.length();
		if(x.equals(y)){
			return false;
		}
		for(int i=0; i<len;i++){
			if(x.equals(y)){
				return true;
			}
			//shift
			x = (x.substring(1) + x.charAt(0));
		}
		return false;
	}
}
