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.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

class Algorithm{	
	int A;
	int B;
	int half;
	ArrayList<Key> map;
	int counter;
	
	public Algorithm(String line){
		Scanner scan = new Scanner(line);
		A = scan.nextInt();
		B = scan.nextInt();
		half = (B-A)/2;
		map = new ArrayList<Key>();
		counter = 0;
	}
	
	public int getOutput(){
		return counter;
	}

	public void solve(){
		for(int x = B; x >= A; x--){

			String xString = Integer.toString(x);
			for(int y = 1; y<=xString.length()/2; y++){
				for (int i = 0; i<xString.length(); i++){
					String old = xString;
					xString = xString.substring(y, xString.length());
					xString = xString.concat(old.substring(0,y));
					if(!xString.equals(old) && xString.charAt(0) != '0' && old.charAt(0) != '0'){
						int m = Integer.parseInt(old);
						int n = Integer.parseInt(xString);
						Key check = new Key(m, n);
						if(A <= m && m <= B && A <= n && n <= B && (!map.contains(check))){
							map.add(check);
							//System.out.println(m + "  " + n);
							counter++;
						}
					}
				}
			}
		}
	}
}

class Key {
	public int N;
	public int M;
	public Key(int n, int m){
		N = n;
		M = m;
	}
	
	public boolean equals(Object o){
		if(o.getClass().equals(this.getClass())){
			Key toCompare = (Key)o;
			if((toCompare.N == this.N && toCompare.M == this.M)  || (toCompare.N == this.M && toCompare.M == this.N)){
				return true;
			}
		}
		return false;
	}

}



public class Main {
	
	public static void main(String[] args) throws IOException{
		File inputFile = new File("input.txt");
		Scanner scan = new Scanner(inputFile);
		int loopCount = scan.nextInt();
		scan.nextLine();
		FileWriter outputFile = new FileWriter("output.txt");
		for(int i = 1; i <= loopCount; i++){
			Algorithm start = new Algorithm(scan.nextLine());
			start.solve();
			outputFile.write("Case #"+i+": " + start.getOutput());
			if(i < loopCount){
				outputFile.write("\r\n");
			}
		}
		outputFile.close();
	}
}
