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.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

public class Runner {

	class ll {
		public lln f;
		public lln l;
	}

	class lln {
		public Object v;
		public lln n;
	}

	private static Scanner sc;

	public static int gi() {
		return Integer.parseInt(sc.next());
	}

	public static String gn() {
		return sc.next();
	}

	public static void main(String[] args) throws IOException {
		System.setIn(new FileInputStream("C-small-attempt2.in"));
		System.setOut(new PrintStream("output.txt"));

		sc = new Scanner(System.in);

		int N = gi();

		for (int z = 0; z < N; z++) {

			int o = gi();
			int t = gi();

			int c = 0;

			for (int m = o + 1; m <= t; m++) {
				for (int n = o; n < m; n++) {
					String ms = new Integer(m).toString();
					String ns = new Integer(n).toString();

					ns = ns.substring(ns.length() - 1) + ns.substring(0, ns.length() - 1);

					for (int i = 0; i < ms.length() - 1; i++) {
						//System.out.println("M: " + ms + " N: " + ns);
						if(ns.equals(ms)) {
							c++;
							break;
						}
						//System.out.println("Pre: " + ns + " ms: " + ms);
						ns = ns.substring(ns.length() - 1) + ns.substring(0, ns.length() - 1);
						//System.out.println("Post: " + ns + " i: " + i);
					}
				}
			}

			System.out.format("Case #%d: %d\r\n", z + 1, c);
		}
	}

}
