import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package qr;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

public class C {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner scanner = new Scanner(new File("C-large.in"));
    int tcn = scanner.nextInt();
    int tc = 1;
    while (tc <= tcn) {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int y = 0;
      // System.out.printf("%d %d\n", a, b);
      if (a > 9) {
        y = 0;
        for (int n = a; n < b; n++) {
          String ns = Integer.toString(n);
          // System.out.println("ns=" + ns);
          int len = ns.length();
          HashSet<Integer> sss = new HashSet<Integer>();
          for (int i = 1; i < len; i++) {
            String ns1 = ns.substring(0, i);
            String ns2 = ns.substring(i, len);
            // System.out.printf("ns1=%s ns2=%s\n",ns1,ns2);
            if (ns2.charAt(0) == '0')
              continue;
            String ms = ns2 + ns1;
            // System.out.println("ms="+ms);
            int m = Integer.parseInt(ms);
            if (sss.contains(m))
              continue;
            if (n < m && m <= b) {
              y++;
              sss.add(m);
//              System.out.printf("%d <= %d < %d <= %d\n", a, n, m, b);
            }
          }
        }
      }
      System.out.printf("Case #%d: %d\n", tc, y);

      tc++;
    }
  }
}
