import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;


public class main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		BufferedReader dat=new BufferedReader(new FileReader("input"));
		int BRCASE=Integer.parseInt(dat.readLine());
		for(int ic=1;ic<=BRCASE;ic++){
			String str[]= dat.readLine().split(" ");
			System.out.println("Case #"+ic+": "+test(Integer.parseInt(str[0]),Integer.parseInt(str[1])));
		}
	}
	public static int test(int n, int m){
		boolean [] pominati= new boolean[m-n+10];
		int rez=0;
		for(int i=n;i<=m;i++){
			int ttl=0;
			int tmp=i;
			if(!pominati[tmp-n]){
				do{
					if(tmp>=n && tmp<=m){
						if(!pominati[tmp-n]){
							pominati[tmp-n]=true;
							ttl++;
						}
					}
					tmp=rotate(tmp);
				}while(tmp!=i);
			}
			rez+=(ttl>=2)?comb(ttl,2):0;
		}
		return rez;
		
	}
	public static int rotate(int x){
		int pow = (int)Math.log10(x);
		do{
			if(x%10!=0){
				x = (int) ((int)x%10*Math.pow(10, pow)+(int)x/10);
				break;
			}else{
				x = (int) ((int)x%10*Math.pow(10, pow)+(int)x/10);
			}
		}while(true);
		return x;
	}
	
	public static int fact(int x){
		int ret=1;
		for(int i=1;i<=x;i++){
			ret*=i;
		}
		return ret;
	}
	public static long comb(int n, int k){
		if(k>(n-k))
		k=n-k;
		long c=1;
		for(int i=0; i<k; i++)
		{
			c=c*(n-i);
			c=c/(i+1);   
		}
		return c;
	}
}
