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));
	}
}


public class RecycleNumber {
	
	int count=0;
	public RecycleNumber(int A,int B){
		for(int n=A;n<B-1;n++){
			for(int m=n+1;m<=B;m++){
				if(isRecycledPair(n,m)){
					count++;
				}
			}
		}
	}
	
	public int getCount() {
		return count;
	}


	boolean isRecycledPair(int a,int b){
		String sA=a+"";
		String sB=b+"";
		//start from 
		int countB=sB.length();
		int countA=sA.length();
		if(countA!=countB)return false;
		for(int i=0;i<sA.length();i++){
			if(sA.charAt(i)==sB.charAt(0)){
				if(sA.charAt(i)=='0') continue;
				if(compare(sA,i,sB))
					return true;
			}
		}

		return false;
	}
	private boolean compare(String sA, int i, String sB) {
		// TODO Auto-generated method stub
		int count=0;
		int length=sB.length();
		for(int j=i,k=0;count<length;k++,count++,j=(j+1)%length){
			if(sA.charAt(j)!=sB.charAt(k)){
				return false;
			}
		}
		return true;
	}

}
