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


public class Solution {
	
	public static boolean isRecycled(int n, int m){
		String strN = Integer.toString(n);
		String strM = Integer.toString(m);
		
		String tmp = strN;
		for(int i=0; i<strN.length(); i++){
			StringBuilder tmpStr = new StringBuilder();

			tmpStr.append(tmp.charAt(tmp.length()-1));
			
			for(int j=0; j<tmp.length()-1; j++){
				tmpStr.append(tmp.charAt(j));
			}
			
			tmp = tmpStr.toString();
			
			if(tmp.equals(strM)){
				//System.out.println("RecycledNumber : " + strN + ", " + strM);
				return true;
			}
		}
		
		return false;
	}
	
	public static int calc(int A, int B){
		int ret = 0;
		
		for(int i=A; i<=B; i++){
			for(int j=i+1; j<=B; j++){
				if(isRecycled(i, j)){
					ret ++;
				}
			}
		}
		
		return ret;
	}
	
	public static void main(String[] args){
        if(args.length == 0){
            System.exit(1);
        }

        try{
            FileReader fr = new FileReader(args[0]);
            BufferedReader br = new BufferedReader(fr);
            
            FileOutputStream fos = new FileOutputStream("output.out");
            OutputStreamWriter osw = new OutputStreamWriter(fos , "UTF-8");
            BufferedWriter bw = new BufferedWriter(osw);
            
            String tmp_str;
            
            tmp_str = br.readLine();
            
            int numOfCases = Integer.parseInt(tmp_str);
            int caseIndex = 0;

            while((tmp_str = br.readLine()) != null){
            	caseIndex++;

                StringTokenizer st = new StringTokenizer(tmp_str, " ");
                int numOfTokens = st.countTokens();
                String[] tokenOfLine = new String[numOfTokens];
                for(int i=0; i<numOfTokens; i++){
                	tokenOfLine[i] = st.nextToken();
                }
                
                int A = Integer.parseInt(tokenOfLine[0]);
                int B = Integer.parseInt(tokenOfLine[1]);
                
                int ret = calc(A, B);
                
                System.out.println("Case #" + caseIndex + ": " + ret);
                
            	if(caseIndex==numOfCases){
                	bw.write("Case #" + caseIndex + ": " + ret);
            	}else{
                	bw.write("Case #" + caseIndex + ": " + ret + "\n");
            	}
            }
            br.close();
            bw.close();
            osw.close();
            fos.close();

 
        }
        catch(IOException e){
            e.printStackTrace();
            System.exit(1);
        }

	}
}
