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 void main(String args[]){
		try{
		FileInputStream fin=new FileInputStream("C:\\Program lang\\Google Code Jam\\input01.txt");
		DataInputStream datain=new DataInputStream(fin);
		
		BufferedReader br=new BufferedReader(new InputStreamReader(datain));
		File file = new File("C:\\Program lang\\Google Code Jam\\output01.txt");
		
		BufferedWriter bw=new BufferedWriter(new FileWriter(file));
		
		int T=Integer.parseInt(br.readLine());
		for(int j=0;j<T;j++){
			StringTokenizer st=new StringTokenizer(br.readLine());
			String sA=st.nextToken();
			String sB=st.nextToken();
			int A=Integer.parseInt(sA);
			int B=Integer.parseInt(sB);
			int l[]=new int[sA.length()];
			int u[]=new int[sB.length()];
			int count=0;
			for(int i=0;i<sA.length()-1;i++){
				l[i]=Integer.parseInt(sA.substring(i,i+1));
				u[i]=Integer.parseInt(sB.substring(i,i+1));
			}
			l[sA.length()-1]=Integer.parseInt(sA.substring(sA.length()-1));
			u[sB.length()-1]=Integer.parseInt(sB.substring(sB.length()-1));
			
			if(l.length==2){
				ArrayList<Integer> num=new ArrayList<Integer>();
				//ab
				for(int i=A;i<B+1;i++){
					if(!num.contains(i)){
						int unit=i%10;
						int tens=i/10;
						if(unit!=tens){
							int swap=unit*10+tens;
							if(A<=swap && swap<=B)	{
								num.add(swap);
								count++;	
							}
						}
					}
				}
				
			}
			else if(l.length==3){
					// abc
				ArrayList<Integer> num=new ArrayList<Integer>();
				// A is at 0th position
				// r is at r-A
				for(int i=A;i<B+1;i++){
					if(!num.contains(i)){
					String s1=Integer.toString(i);
					int p=Integer.parseInt(s1.substring(1)+s1.substring(0,1));  //bca
					int q=Integer.parseInt(s1.substring(2)+s1.substring(0,2));  //cab
					if(p==q){}
					else if(p>=A && p<=B){
						count++;
						num.add(p);
						if(q>=A && q<=B){
							count=count+2;
							num.add(q);
						}
					}
					else if(q>=A && q<=B)	{
						count++;
						num.add(q);
					}
				}
				}
			}
			bw.write("Case #"+(j+1)+": "+count);
			bw.newLine();
		}
		bw.close();
		}catch(Exception e){
			System.out.println(e);
		}
	}

}

