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.*;
import java.io.*;

public class Samir{
   public static void main(String[] args) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      Formatter formatter = new Formatter(System.out);
      int T = Integer.parseInt(br.readLine());
      int A,B;
      String[] lineParts;
      int lineNum=1;
      while(T-->0){
	 lineParts=br.readLine().split("\\s");
	 A=Integer.parseInt(lineParts[0]);
	 B=Integer.parseInt(lineParts[1]);
	 formatter.format("Case #%d: %d\n",lineNum++,cycles(A,B));
      }
      formatter.close();
   }
   private static int cycles(int A, int B){
      int pairs= 0;
      for(int n=A;n<B;n++){
	pairs+=solve(n,B); 
      }
      return pairs;
   }
   private static int solve(int n, int B){
      int pairs=0;
      int m=n;
      int q,r;
      int nLen=(""+n).length();
      LinkedList<Integer> restQueue=new LinkedList<Integer>();
      for(int i=0;i<nLen;i++){
	 q=m/10;
	 r=m%10;
	 m=q;
	 restQueue.add(r);
	 if(r!=0){
	    int len=(""+m).length();
	    while(!restQueue.isEmpty()){
	       m+=restQueue.removeFirst()*Math.pow(10,len++);
	    }
	    if(m>n && m <=B) pairs++;
	 }
      }
      return pairs;
   }
}
