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 q2012;

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

public class RecycledNumbers {
   public static void main(String[] args) throws Exception {
      long start = System.currentTimeMillis();
      String input = "C-large.in";
      String output = "C-large.out";

      Scanner scan = new Scanner(new BufferedReader(new FileReader(input)));
      PrintWriter pw = new PrintWriter(new BufferedWriter(
            new FileWriter(output)));

      int T = Integer.parseInt(scan.nextLine());
      for (int t = 1; t <= T; t++) {
         String[] info = scan.nextLine().split(" ");
         int A = Integer.parseInt(info[0]);
         int B = Integer.parseInt(info[1]);
         HashSet<Integer> set = new HashSet<Integer>();
         long count = 0;
         for (int i = A; i <= B; i++) {
            String num = String.valueOf(i);
            int len = num.length();
            set.clear();
            for (int j = 1; j < len; j++) {
               String n = num.substring(j) + num.substring(0, j);
               int s = Integer.parseInt(n);
               if (s > i && s <= B)
                  set.add(s);
            }
            count += set.size();
         }
         System.out.println("Case #" + t + ": " + count);
         pw.println("Case #" + t + ": " + count);
      }

      scan.close();
      pw.close();

      long end = System.currentTimeMillis();
      System.out.println((end - start) / 1000.0);
   }
}