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.*;

class RecycledNumbers
{
  public static void main(String[] args)
  {
    try {
    //parse the input
    FileInputStream fstream = new FileInputStream(args[0]);
    DataInputStream dstream = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(dstream));
    String line = "";

    int numCases = Integer.parseInt(br.readLine());
//System.out.println("num cases: " + numCases);

    for(int lineIdx = 0; lineIdx < numCases; lineIdx++)
    {
      line = br.readLine();
      String[] words = line.split(" ");
      int n = Integer.parseInt(words[0]);
      int m = Integer.parseInt(words[1]);
//System.out.println(n + " " + m);
      int numRecycledNumbers = 0;
      for(int i = n; i <= m; i++)
      {
        for(int j = i+1; j <= m; j++)
          if(countRecycledNumbers(i, j))
            numRecycledNumbers++;
      }
//System.out.println(numRecycledNumbers);
      // write output
      BufferedWriter out = new BufferedWriter(new FileWriter("outfilename", true)); 
      out.write("Case #" + (lineIdx+1) + ": " + numRecycledNumbers + "\n");
      out.close(); 
    }
  }
  catch(FileNotFoundException ex)
  {
    System.out.println(ex);
  }
  catch(IOException ex)
  {
    System.out.println(ex);
  }
  }

  static boolean countRecycledNumbers(int n, int m)
  {
    String nStr = "" + n;
    String mStr = "" + m;
//System.out.println(nStr + " " + mStr);
    if(nStr.length() == mStr.length())
    {
//System.out.println("length condition hit");
      if( (nStr+nStr).indexOf(mStr) >= 0 )
      {
//        System.out.println("index condition hit");
        return true;
//System.out.println(numRecycledNumbers);
      }
    }
    return false;
  }
}


