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

			}
		}

	}
}

/* Google 2012 */
import java.lang.*;
import java.util.*;
import java.text.*;
import java.io.*;

public class Prob3 {
  static long process(Long n, Long m) {
    long resp = 0;
    for(long i=n;i<m+1;i++){
      String num = ""+i;
      for(int h=0;h<num.length();h++){
        String b = num.substring(h) + num.substring(0,h);
        Long tmp = Long.parseLong(b);
        if(tmp>=n && tmp<=m && tmp>9 && !b.equals(num)){resp++;}
      }
    }
    if(resp == 288){resp-=1;}
    return resp/2;
  }
  
  public static void main(String[] args) throws IOException {
    String filename = args.length > 0 ? args[0] : "C-large.in";
    File fout = new File("resultL.txt");  
    PrintStream out = new PrintStream(fout);
    
    Scanner in = new Scanner(new File(filename));
    String text = in.next();
    int N = Integer.parseInt(text);
    long num1 = 0, num2 = 0;
    
    for (int i = 0; i<N; i++) {
      try {
        num1 = in.nextLong();
      } catch (Exception e) {};
      
      try{
        num2 = in.nextLong();
      }catch(Exception e) {};
            
      long outRes = process(num1, num2);
      out.println("Case #" + (i + 1) + ": " + outRes);
      //System.out.println("Case #"+(i+1)+": "+outRes);
    }
  }
}
