import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.HashSet;


public class A {
	
public static int a(String str){
	
	int retVal = 0;
	
	String arr[] = str.split(" ");
	int n = Integer.parseInt(arr[0]);
	int m = Integer.parseInt(arr[1]);
	
	for(int i = n ; i < m; i++){
		String cur = Integer.toString(i);
		cur += cur;
		HashSet<String> set = new HashSet<String>();
		for(int j = 1; j < cur.length()/2 ; j++){			
			String val = cur.substring(j, j+cur.length()/2);
			int intVal = Integer.parseInt(val);			
			if(set.add(val) && intVal > i && intVal <= m){				
				retVal++;
				//System.out.println(retVal + ":" +cur.substring(cur.length()/2)+" : "+intVal);
			}
		}
		
	}
	
	
	return retVal;
	
}	
	
public static void main(String args[]){
		
		File file = new File("C-small-attempt0.in");
		
		int T = 0;
		try{
			  FileInputStream fstream = new FileInputStream(file);
			
			  DataInputStream in = new DataInputStream(fstream);
			  BufferedReader br = new BufferedReader(new InputStreamReader(in));
			  String strLine;
			  if ((strLine = br.readLine()) != null)   {
				  T = Integer.parseInt(strLine);
			  }
			  int currentCase = 1;
			  while(T > 0 && currentCase <= T){
						
						String str= br.readLine();
						
						System.out.println("Case #"+currentCase+": " + a(str));
						currentCase++;
					}
			
			  in.close();
			    }catch (Exception e){
			  System.err.println("Error: " + e.getMessage());
			  }
		
		
		
	}
	
}
