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

package year2012.qualification.c;

import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;

public class RecycledNumbers {
	public static void main(String[] args) throws Exception{
		//GCJå±é
		String filename = "src/year2012/qualification/c/C-small-attempt0";
		PrintWriter out = new PrintWriter(new File(filename + ".out"));
		Scanner scan = new Scanner(new File(filename + ".in"));
		
		final int T = scan.nextInt();
		for(int i=0;i<T;i++){
			int ans=0;
			int A = scan.nextInt();
			int B = scan.nextInt();
			
			for(int n=A;n<B;n++){
				int m_memo = -1;
				
				char[] na = String.valueOf(n).toCharArray();
				//ä¾ãã°nã123ã®ã¨ãã231,312ã[A,B)ã®ä¸­ã«ãããèª¿ã¹ã
				//ãã®ä¾ã ã¨k=2åã«ã¼ã
				for(int k=1;k<na.length;k++){
					char[] ma = rotate(na, k);
					int m = Integer.parseInt(String.valueOf(ma));
					if(A <=n
						&& n < m
						&& m <= B
						&& m != m_memo){
						
						m_memo = m;
						ans++;
					}
				}
				
			}
			//åºå
			out.printf("Case #%d: %s\n", i+1, ans);
		}
		out.flush();
	}
	
	
	/**
	 * éåãnåå·¦ã«ããããæ°ããéåãè¿ãã¾ãã
	 * @param in
	 * @param n
	 * @return
	 */
	private static char[] rotate(final char[] in, int n){
		if(n>=in.length){
			throw new IllegalArgumentException("n= " + n + ", in.length = "
					+ in.length + "ã¨ãªã£ã¦ãã¾ããn<in.lengthã«ãã¦ãã ããã");
		}
		char[] out = new char[in.length];
		
		//1,2,3,4ã2åå·¦ã«ãããå ´åãã¾ãå·¦å´ã®2åãéé¿ãã
		char[] tmp = new char[n];
		for(int i=0;i<n;i++){
			tmp[i] = in[i];
		}
		//æ¬¡ã«in[n]ããin[in.length]ã¾ã§ãout[0]ããout[in.length - 2]ã¾ã§ã«ã³ãã¼
		for(int i=0;i<in.length-n;i++){
			out[i] = in[i+n];
		}
		//æå¾ã«out[length-n,length]ã«tmp[0,n]ããå¤ããã©ã
		for(int i=in.length-n;i<in.length;i++){
			out[i] = tmp[i-in.length+n];
		}
		return out;
	}
}
