package qual;

import java.util.Scanner;

public class RecycledNumbers {

	public static void main(String[] args) {
		new RecycledNumbers().run();

	}

	private void run() {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; t++) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			int result = solve(A, B);
			System.out.printf("Case #%d: %d\n", t + 1, result);
		}
	}

	public int solve(int A, int B) {
		int result = 0;
		for (int i = A; i <= B; i++) {
			int dig = (int) Math.log10(A/*same as B*/) + 1;
			int aa = i;
			for (int d = 0; d < dig - 1; d++) {
				aa = (aa % 10) * (int)Math.pow(10, dig - 1) + (aa / 10);
				if (i == aa) {
					break;
				}
				if (i < aa && aa <= B) {
//					System.out.printf("(%d, %d) ", i, aa);
					result++;
				}
			}
		}
		return result;
	}

}

package gcj2012.qual;

import java.util.Arrays;

import common.AbstractRunner;
import common.AbstractRunner.SIZE;

public class C extends AbstractRunner {
		
	
	@Override
	public void handleCase(int caseNumber) throws Exception {
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		
		int pow = 1;
		int n = 0;
		for (int p = A; p>=10; p = p/10) {
			n++;
			pow *= 10;
		}
		
		int res = 0;
		int [] rr = new int[n];
		for (int x=A; x<=B; x++) {
			Arrays.fill(rr, 0);
			int rrlen = 0;
			int xx = x;
			cycle: for (int i=0; i<n; i++) {
				xx = (xx % 10) * pow + (xx/10);
				if (xx > x && xx <=B) {
					for (int j=0; j<rrlen; j++) {
						if (rr[j] == xx) continue cycle;
					}
					rr[rrlen++] = xx;
					res ++;
				}
			}
		}
		
		out.write(Integer.toString(res)+"\n");
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		new C().init(SIZE.small).execute();
	}

}
