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.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;

/**
 * 
 * @author ysan
 *
 */

public class Problem_C_large {
	

	public static void main(String[] args) throws NumberFormatException,
			IOException {

		BufferedReader in = new BufferedReader(new FileReader("C-large.in"));
		BufferedWriter out = new BufferedWriter(new FileWriter("C-large-output0.txt"));
		
		int cases = Integer.parseInt(in.readLine());
		
		 for (int i = 1; i <= cases; i++) {
			 String text = in.readLine().trim();
			 String[] val = text.split(" ");
			 int count = 0;
			 BigInteger lasta = BigInteger.ZERO;
			 BigInteger lastb = BigInteger.ZERO;
			 
			 BigInteger a = new BigInteger(val[0]);
			 BigInteger b = new BigInteger(val[1]);
			 
			 System.out.println(a +" "+b);
			 BigInteger j = a;
			 while(j.compareTo(b) < 0){ 

				 String g = j.toString();
				
				 for(int k=g.length()-1; k>0; k--){
					 BigInteger r = switchIt(g, k);
					 if(r.compareTo(j) > 0 && r.compareTo(b) <= 0 ){
						 System.out.println(" r "+r+" j "+j);
						 if(lasta == j && lastb == r) continue;
						 lasta = j;
						 lastb = r;
						 count++;

					 }
				 }
				 j = j.add(BigInteger.ONE);
			 }
			 out.write("Case #"+ i +": " + count);
			 out.newLine();
		 }
		 
		
		in.close();
		out.close();
		
		
		

	}
	
	
	static BigInteger switchIt(String v, int p){
		BigInteger r= BigInteger.ZERO;
		
		String a = v.substring(p);
		String b = v.substring(0, p);
		
		if(a.charAt(0) != '0'){
			r = new BigInteger(a+b);
		}
		return r;
		
	}
}
