import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

import java.io.*;
class RNumber
{
 public static void main(String args[])throws Exception
 { 
    String[] output;
    BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
	FileOutputStream fo=new FileOutputStream("probB.out");
	int T=Integer.parseInt(in.readLine());
	output=new String[T];
	int[][] inp=new int[T][];
	String temp="";
	for(int i=0;i<T;i++){
	temp=in.readLine();
	inp[i]=new int[]{Integer.parseInt(temp.split(" ")[0]),Integer.parseInt(temp.split(" ")[1])};
	}
	
	for(int i=0;i<T;i++){
	
	 int n=inp[i][0],m=inp[i][1],inc=0;
	 for(int nn=n;nn<=m;nn++){
		for(int mm=n;mm<=m;mm++){
		if(!(mm==nn)){
		 String nS=Integer.toString(nn);
		 String mS=Integer.toString(mm);
		 if(nS.length()==mS.length()){
		  int len=nS.length();
		  for(int ee=0;ee<len;ee++){
		   if(nS.equals(mS)){
		    inc++;
			break;
		   }else{
		    char exp=nS.charAt(0);
			String sa="";
			for(int yy=1;yy<len;yy++){
			sa+=nS.charAt(yy);
			}
			sa+=exp;
			nS=sa;
		   }
		   
		  }
		 }
		}
		}
	  }
	  output[i]="Case #"+(i+1)+": "+(inc/2);
	}
	
	   for(int d=0;d<output.length;d++){
    System.out.println(output[d]);
	if(d==output.length-1){
    fo.write((output[d]).getBytes());}
	else
	fo.write((output[d]+'\n').getBytes());
   }
 }
}