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

			}
		}

	}
}

import java.util.Scanner;
import java.io.*;

public class Q3 {
  public static void main(String []args) throws IOException {
    int numT=0;
    Scanner kb=new Scanner(new File("D:/sample.txt"));
    numT = kb.nextInt();
    int a[] = new int[numT];
    int b[]=new int[numT];
    for (int i = 0; i < numT; i++) {
      a[i] = kb.nextInt();
      b[i]=kb.nextInt();
    }
    for (int i = 0; i < numT; i++) {
      
      System.out.println("Case #"+(i+1)+":"+" "+cal(a[i],b[i]));
    }
    
  }
  
  public static int cal(int A,int B){
    int score=0;
    for(int n=A;n<=B;n++){
      String num = n + "";
      int lastm = 0;
      for(int j=1;j<num.length();j++){
        String s=num.substring(0,j);
        String t = num.substring(j, num.length());
        String sum=t+s;
        int m = Integer.parseInt(sum);
        if (m <= B && m >= A && m != n && m > n && lastm != m) { 
          lastm = m;
          score++; }
      }
    }
    return score;
    
  }
}