import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class C {
	static String CASE = "Case #";
	static String N_L = System.getProperty("line.separator");
	
	static int T, A, B;
	
	public static void main(String[] args) {
		String input = "file/C-small-attempt0.in";
		String output = "file/C-small.txt";
		
		run(input, output);
	}
	
	public static void run(String input, String output) {
		Scanner sc = null;
		Writer writer = null;
		StringBuilder result = new StringBuilder();
		
		try {
			sc = new Scanner(new FileInputStream(input));
			writer = new OutputStreamWriter(new FileOutputStream(output));
			
			T = sc.nextInt();
			
			int one 	= 10;
			int two 	= 100;
			int three 	= 1000;
			int four	= 10000;
			int five	= 100000;
			int six	= 1000000;
			
			for(int i = 1; i <= T; i++) {
				A = sc.nextInt();
				B = sc.nextInt();
				
				Set<Integer> set = new HashSet<Integer>();
				int total = 0;
				
				int mask = 1;
				if(A >= one) {
					if(A < two) {
						mask = one;
					} else if(A < three) {
						mask = two;
					} else if(A < four) {
						mask = three;
					} else if(A < five) {
						mask = four;
					} else if(A < six) {
						mask = five;
					} else {
						mask = six;
					}
					for(int j = A; j <= B; j++) {
						if(set.contains(j)) {
							continue;
						}
						set.add(j);
						int div = j / mask;
						int res = j - (mask * div);
						int target = res * 10 + div;
						while(j != target) {
							if(target >= A && target <= B && !set.contains(target)) {
								total++;
							}
							div = target / mask;
							res = target - (mask * div);
							target = res * 10 + div;
						}
					}
				}
				
				result.append(CASE).append(i).append(": ").append(total);
				if(i != T) {
					result.append(N_L);
				}
				writer.write(result.toString());
				result.setLength(0);
			}
			writer.flush();
			
		} catch(IOException e) {
			e.printStackTrace();
		} finally {
			sc.close();
			try {
				writer.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
