import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}

package qualification.c;

import java.awt.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Core {
  
  public static void main(String[] args) {
    int t, a, b;
    try {
      Scanner scan = new Scanner(new File(args[0]));
      
      t = scan.nextInt();
      for (int i = 1; i <= t; i++) {
        a = scan.nextInt();
        b = scan.nextInt();
        
        System.out.println(solve(i, a, b));
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
  
  public static String solve(int caseNumber, int a, int b) {
    a = Math.max(10, a);
    
    if ((b < 12) || (b <= a))
      return "Case #" + caseNumber + ": 0";
    
    int rev;
    String s;
    Set<Point> set = new TreeSet<Point>(new Comparator<Point>() {
      
      @Override
      public int compare(Point p1, Point p2) {
        if (p1.x != p2.x)
          return p1.x - p2.x;
        
        return p1.y - p2.y;
      }
      
    });
    for (int i = a; i <= b; i++) {
      s = String.valueOf(i);
      for (int j = 0; j < s.length(); j++) {
        rev = Integer.valueOf(s.substring(j) + s.substring(0, j));
        if ((rev > b) || (rev <= i)
            || (String.valueOf(rev).length() != s.length()))
          continue;
        
        set.add(new Point(i, rev));
      }
    }
    
    return "Case #" + caseNumber + ": " + set.size();
  }
  
  /*
   * public static String solve(int caseNumber, int a, int b) {
   * if (b < 12)
   * return "Case #" + caseNumber + ": 0";
   * 
   * a = Math.max(10, a);
   * 
   * int n = 0;
   * String s, bStr;
   * bStr = String.valueOf(b);
   * char f;
   * int check;
   * for (int i = a; i <= b; i++) {
   * s = String.valueOf(i);
   * System.out.println("STR: " + s);
   * f = s.charAt(0);
   * for (int j = 1; j < s.length(); j++) {
   * if ((s.charAt(j) < f) || (s.charAt(j) > bStr.charAt(0)))
   * continue;
   * 
   * check = 0;
   * if (s.charAt(j) == f) {
   * while (((j + check) < s.length()) && (s.charAt(j + check) == f))
   * check++;
   * if ((j + check) == s.length()) {
   * if (i == 449)
   * System.out.println(j + " : " + check + " : " + s.length());
   * continue;
   * }
   * }
   * 
   * check = 0;
   * if (Integer.valueOf("" + s.charAt(j)) <= Integer.valueOf(""
   * + bStr.charAt(0))) {
   * while (((j + check) < s.length())
   * && (Integer.valueOf("" + s.charAt(j + check)) <= Integer
   * .valueOf("" + bStr.charAt(check))))
   * check++;
   * 
   * if ((j + check) != (s.length()))
   * continue;
   * }
   * 
   * System.out.println(s + " : " + s.substring(j) + s.substring(0, j));
   * n++;
   * }
   * }
   * 
   * return "Case #" + caseNumber + ": " + n;
   * }
   */
}