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.util.*;
import java.io.*;

public class B {
  private static boolean isRecyclePair(int n, int m){
    String n_str=""+n;
    String m_str=""+m;
    for(int i=0; i<n_str.length(); i++){
      String candidate=n_str.substring(i)+n_str.substring(0, i);
      if(m_str.equals(candidate)) return true;
    }
    return false;
  }
  private static void gcjMethod(String[] input){
    int a=Integer.parseInt(input[0]);
    int b=Integer.parseInt(input[1]);
    int res=0;
    // System.out.format("A=%d, B=%d\n", a, b);
    for(int i=a; i<=b; i++)
      for(int j=i+1; j<=b; j++)
        if(isRecyclePair(i, j)) res++;
    System.out.println(res);
    return;
  }

  public static final void main(final String[] args) {
    String line;
    int numCase;
    String[] input;

    BufferedReader d = new BufferedReader(new InputStreamReader(System.in));
    try{
      numCase=Integer.parseInt(d.readLine());
      for(int i=0; i<numCase; i++){
        line=d.readLine();
        input=line.split(" ");
        System.out.print(String.format("Case #%d: ", i+1));
        gcjMethod(input);
      }
    }
    catch(Exception e){
      System.out.println(e);
    }
  }
}