import java.util.*;
import java.io.*;

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public abstract class FileWrapper {

	protected static final String CASE = "Case #";
	protected static final String OUTPUT = "result.out";
	protected int caseNum = 0;
	protected String output[] = null;
	private FileReader fr = null;
	private BufferedReader br = null;
	private FileWriter fw = null;
	private BufferedWriter bw = null;

	protected void openReadFile(String fileName) throws Exception {
		this.fr = new FileReader(fileName);
		this.br = new BufferedReader(this.fr);
	}

	protected void closeReadFile() throws Exception {
		this.br.close();
		this.fr.close();
	}

	protected String readLine() throws Exception {
		return this.br.readLine();
	}
	
	protected boolean isFileReady() throws Exception {
		return this.br.ready();
	}
	
	protected abstract void processInput(String fileName);
	
	private void openWriteFile(String fileName) throws Exception {
		this.fw = new FileWriter(fileName);
		this.bw = new BufferedWriter(this.fw);
	}

	private void closeWriteFile() throws Exception {
		this.bw.close();
		this.fw.close();
	}

	private void writeLine(String line) throws Exception {
		this.bw.write(line);
		this.bw.newLine();
	}
	
	protected void processOutput(String fileName) {
		try{
			this.openWriteFile(fileName);
			for (int i=0; i<this.caseNum; i++) {
				this.writeLine(this.output[i]);
			}
			this.closeWriteFile();
		}catch(Exception e){}
	}
	
	protected abstract void calculate();

}