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 qualificationRound;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet;

public class P3 {
	public static int recycle(int j, int b) {
		int ret = 0;
		String old = Integer.toString(j);
		int size = old.length();
		HashSet<String> app = new HashSet<String>();
		for (int i = 1; i < size; ++i) {
			String tmp = old.substring(i) + old.substring(0, i);
			int num = Integer.parseInt(tmp);			
			if (num <= b && num > j && !app.contains(tmp)) {				
				ret++;
				app.add(tmp);
			}
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new FileReader("C-small-attempt0.in"));
		FileWriter fw = new FileWriter("out.txt");
		int t = Integer.parseInt(br.readLine());
		for (int i = 1; i <= t; ++i) {
			String line = br.readLine();
			String A = line.split(" ")[0];
			String B = line.split(" ")[1];
			int a = Integer.parseInt(A);
			int b = Integer.parseInt(B);
			int num = 0;
			for (int j = a; j <= b; ++j) {
				num += recycle(j, b);
			}
			fw.append("Case #" + i + ": " + num + "\n");
		}
		br.close();
		fw.close();
	}
}
