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

public class C_RecycledNumbers {
	static String name = "C-small-attempt0";
	static boolean been[];

	static int f(int a, int b) {
		//System.out.println(a + " " + b);
		been[a] = true;
		int c = a;
		int num = 1, k = -1, ans = 1;
		while (c != 0) {
			c /= 10;
			num *= 10;
			k++;
		}
		num /= 10;
		c = a;
		for (int i = 0; i < k; i++) {
			int rem = a % 10;
			a /= 10;
			a += rem * num;
			if (a <= b && a >= c) {
				if (been[a])
					continue;
//				System.out.println(a+" "+c);
				been[a] = true;
				ans++;
			}
		}
		return ans * (ans - 1) / 2;

	}

	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(name + ".in"));
		PrintWriter out = new PrintWriter(name + ".out");
		int t = Integer.parseInt(in.readLine()), caseN = 1;
		been = new boolean[10000000];
		while (caseN <= t) {
			long ans = 0;
			StringTokenizer tok = new StringTokenizer(in.readLine());

			int a = Integer.parseInt(tok.nextToken()), b = Integer.parseInt(tok
					.nextToken());
			for (int i = a; i <= b; i++) {
				ans += f(i, b);
			}
			Arrays.fill(been, a, b + 10, false);

			out.print("Case #");
			out.print(caseN++);
			out.print(": ");
			out.println(ans);
		}
		out.flush();
	}
}
