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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;


public class RecycledNumbers {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			BufferedReader br = new BufferedReader(new FileReader("/Users/William/Desktop/C-small-attempt0.in"));
			String strLine;
			
			FileWriter fostream = new FileWriter("/Users/William/Desktop/output.txt");
			BufferedWriter out = new BufferedWriter(fostream);
			
			strLine = br.readLine();
			int numOfLine = Integer.parseInt(strLine);
			
			for (int i=1;i<numOfLine+1;i++) {
				strLine = br.readLine();
				
				String splitedStr[] = strLine.split(" ");
				String first = splitedStr[0];
				String second = splitedStr[1];
				
				int firstNum = Integer.parseInt(first);
				int secondNum = Integer.parseInt(second);
								
				int count = 0;
				for (int k=firstNum;k<=secondNum;k++) {

					Integer kInt = new Integer(k);
					String kStr = kInt.toString();
					
					HashMap<Integer, ArrayList<Integer>> map = new HashMap<Integer, ArrayList<Integer>>();

					for (int j=1;j<kStr.length();j++) {
						String digit = kStr.substring(kStr.length()-j);
						String rest = kStr.substring(0, kStr.length()-j);
						
						String newStr = digit + rest;
						if (newStr.charAt(0)=='0') {
							continue;
						}
						
						int newNum = Integer.parseInt(newStr);
						
						ArrayList<Integer> list;
						if (map.get(k)==null) {
							list = new ArrayList<Integer>();
						}
						else {
							list = map.get(k);
						}
						
						boolean contains = false;
						for (Integer m : list) {
							if (m.intValue()==newNum) {
								contains = true;
								break;
							}
						}
						
						if (contains) {
							continue;
						}
						
						list.add(newNum);
						map.put(k, list);
						
						if ((newNum>k) && (newNum<=secondNum)) {
//							System.out.println("(" + k + " , " + newNum + ")");
							count ++;
						}
					}
				}
				System.out.println("Case #" + i + ": " + count);
				out.write("Case #" + i + ": " + count + "\n");
			}
			out.close();
			br.close();
		}
		catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}
	}

}
