package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

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

/**
 *
 * @author yo7
 */
public class ReceycledNumper2 {
    public static void main(String[] args) throws FileNotFoundException, IOException {
    BufferedReader f = new BufferedReader(new FileReader("C-small-attempt0.in"));
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
    Scanner sc=new Scanner(f);
    int n=sc.nextInt();
    sc.nextLine();
    int num1,num2;
    for(int Linenumper=1;Linenumper<=n;Linenumper++){
        String line=sc.nextLine();
        String[] tokens=line.split(" ");
        num1=Integer.parseInt(tokens[0]);
        num2=Integer.parseInt(tokens[1]);
        if(num1<10)
        {
            String ss="Case #"+Linenumper+": 0";
            out.println(ss);
            continue;
        }
        int count=0;
        for(int k=num1;k<num2;k++)
          for(int i=k;i<num2;i++)
          {
              String str1=k+"";
              String str2=i+1+"";
              int len=str1.length();
              for(int j=1;j<len;j++)
              {
                  String end=str1.substring(len-j,len);
                  String front=str1.substring(0,len-j);
                  String newstring=end+front;
                  if(newstring.equals(str2))
                  {
                      count++;
                      j=str1.length();
                  }
              }
          }
          String ss="Case #"+Linenumper+": "+count;
          out.println(ss);
    }
      
    out.close();                                  // close the output file
    System.exit(0);                               // don't omit this!
    }
}
