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 Main {

	static private String formatPair(int toMove, String num1) {
		String back = num1.substring(num1.length() - toMove);
		String front = num1.substring(0,num1.length() - toMove);
		return (back + front);
	}

	static private int getDistinctPairs(int v1,int v2) {
		String num1 = Integer.toString(v1);
		String num2 = Integer.toString(v2);
		
		if (num1.length() != num2.length()) return 0;
		
		for (int i = 1; i < num1.length();i++) {
			String match = formatPair(i,num1);
			if (match.equals(num2)) 
				return 1;
		}
		
		return 0;
	}
	
	static int getDistinctPairsBetween(int a, int b) {
		int count = 0;
		//generate all possible values
		for (int i=a; i <= b; i++) 
			for (int j=i+1;j <= b; j++) {
				
				boolean valid = (i >= a && i < j && j > i && j <= b);	
				if (valid) 
					count += getDistinctPairs(i,j);	
			}
		return count;
	}
		
	static public void main(String args[]) {
		
		try{
		  FileWriter fstream = new FileWriter("output.out");
		  BufferedWriter out = new BufferedWriter(fstream);
		  
		try {
		  BufferedReader input =  new BufferedReader(new FileReader(new File(args[0])));
		  try {
			String line = null; 
			
			line = input.readLine();
			int count = Integer.parseInt(line);
			
			for (int i =0; i<count;i++) {
				line = input.readLine();
				String[] values = line.split(" ");
				int pairs = getDistinctPairsBetween(Integer.parseInt(values[0]),Integer.parseInt(values[1]));
				out.write("Case #" + (i+1) + ": " + pairs);
				out.newLine();
			}
			
		  }
		  finally {
			input.close();
		  }
		}
		catch (IOException ex){
		  ex.printStackTrace();
		}
		
		out.close();
	  }catch (Exception e){
		System.err.println("Error: " + e.getMessage());
	  } 
	}
}
