import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;

public class GCJ12QRC
{
	private static int a, b, d;
	private static long c;
	private static String output, newline = System.getProperty("line.separator");

	public static void fun()
	{
		String s;
		int i, j, k;
		c = d = 0;
		for(i=a; i>0; i/=10)
			d++;

		for(i=a; i<b; i++) {
			s = "" + i;
			for(j=1; j<d; j++) {
				k = Integer.parseInt(s.substring(j) + s.substring(0, j));
				if(k>i && k<=b) {
					System.out.println(i + " " + k);
					c++;
				}
			}
		}
	}

	public static void main(String[] args) throws IOException
	{
		long t2, t1 = System.currentTimeMillis();
		output = "";
		Scanner sc = new Scanner(new File("C-small-attempt0.in"));
		int ntc = sc.nextInt();

		for(int w=1; w<=ntc; w++)
		{
			a = sc.nextInt();
			b = sc.nextInt();
			fun();
			output += "Case #" + w + ": " + c + newline;
		}
		sc.close();

		OutputStream fo = new FileOutputStream("C-small-attempt0.out");
		fo.write(output.getBytes());
		fo.close();
		t2 = System.currentTimeMillis();
		System.out.println( "Time in millis : " + (t2-t1) );
	}
}
