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.util.*;
import java.io.*;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;

public class q_b {
	
	public static void main(String [] args) {		
		
		// Open files
		try {
			// Open input file
			FileInputStream iStream = new FileInputStream("Sample.in");
			// Get the DataInputStream object
			DataInputStream in = new DataInputStream(iStream);
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			
			System.out.println("Input file opened");
			
			// Create output file 
			FileWriter oStream = new FileWriter("Sample.out");
			BufferedWriter out = new BufferedWriter(oStream);
			
			System.out.println("Output file opened");
			
			// Read File Line By Line (and read first line)
			String strLine = br.readLine();
			int testN = Integer.parseInt(strLine);
			int caseN = 1;
			while ((strLine = br.readLine()) != null) {
 
				String[] nums = strLine.split(" ");
				
				int a = Integer.parseInt(nums[0]);
				int b = Integer.parseInt(nums[1]);
				
				int nDigits = nums[0].length();

				out.write("Case #" + caseN + ": ");
				System.out.println(a+" "+b+"             \tCase #" + caseN + ": ");
				
				if (nDigits < 2) {
					out.write("0");
					out.newLine();
					System.out.println("0");
					caseN++;
					continue;
				}
				
				int pow = 1;
				for(int i=0;i<nDigits-1;i++) pow = pow *10;
				
				int nPairs = 0;
					
				for (int i=a; i <= b; i++) {			
					
					int j = i;			
					int k = j;
					System.out.print(j+" ");
					int m = 0;

					for(int z=1; z<nDigits; z++) {
						m = j % 10;
						
						j = j/10 + m*pow;
						
						System.out.print(j+" ");
						if (j <= i || m == 0 || j > b || j == k) continue;
						nPairs++;
						System.out.print("*** ");
						k = j;
					}
					System.out.println();
				}

				String result = Integer.toString(nPairs);
				System.out.println(result);
				out.write(result);
				if (caseN != testN) out.newLine();
				caseN++;
			}
			// Close the streams
			in.close();
			out.close();
		}catch (Exception e) {// Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}		
	}

}