import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t=sc.nextInt();
		int casos=1, a, b, n, m, cont;
		while(t!=0){
			a=sc.nextInt();
			b=sc.nextInt();
			if(a>b){
				int aux=a;
				a=b;
				b=aux;
			}
			System.out.printf("Case #%d: ",casos++);
			if(a==b){
				System.out.printf("%d\n",0);
			}else{
				cont=0;
				for(n=a;n<b;n++){					
					for(m=n+1;m<=b;m++){					
						if(isRecycled(n,m)) cont++;
					}
				}
				System.out.printf("%d\n",cont);
			}
			t--;
		}		
	}
	public static boolean isRecycled(int n1, int n2){
		String s1, s2, aux;
		s1 =  String.valueOf( n1 );
		s2 =  String.valueOf( n2 );		
		boolean r = false;		
		for(int i=0;i<s1.length();i++){
			aux="";
			aux=s1.substring(i,s1.length())+s1.substring(0,i);
//			System.out.println(aux);
			if(aux.equals(s2)){
				r=true;
				break;
			}
		}		
		return r;
	}
}

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

public class Main {

	final static String FNAME = "A-small-practice";

	public BufferedReader in;

	public PrintWriter out;

	
	
	void open() throws IOException {
		in = new BufferedReader( new FileReader( new File( FNAME + ".in" ) ) );
		out = new PrintWriter( new File( FNAME + ".out" ) );
	}

	void close() throws IOException {
		out.close();
	}

	void run() throws IOException {
		
		
		String str = in.readLine();
		String[] input;
		int min,max,firstdigit, count;
		String newNum, converted;
		int num = new Integer( str );
		int[] array;
		for(int i = 0; i<num ; i++){
			
			input = in.readLine().split(" ");
			min = new Integer(input[0]);
			max = new Integer(input[1]);
			count=0;
			
			for(int j=min;j<=max; j++)
			{
				newNum=""+j;
				array = new int[input[0].length()-1];
				for(int k=1;k<newNum.length();k++)
				{
					boolean notsame = true;
					converted = newNum.substring(k) + newNum.substring(0,k);
					for(int h =0;h<k-1;h++)
					{
						if(new Integer(converted) == array[h] )
						{
							notsame = false;
						}
					}
					array[k-1] = new Integer(converted);
					if(new Integer(converted)>new Integer(newNum) && new Integer(converted)<=max && notsame)
					{
						count++;
					}
				}
			}
			
			out.println( "Case #" + (i+1) + ": "+ count );
			
		}
		
	}

	public static void main( String[] args ) throws IOException {
		new Thread() {

			public void run() {
				try {
					Main solution = new Main();
					solution.open();
					solution.run();
					solution.close();
				} catch ( Exception e ) {
					throw new RuntimeException( e );
				}
			}
		}.start();
	}
}