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 c;
import java.io.*;
/**
 * Google Code Jam C
 * @author hang
 *
 */

public class Main {
	public static void main(String args[]) throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String n_str = br.readLine();
		int n_int = Integer.parseInt(n_str);
		int min, max;
		for(int i = 1;i<=n_int;i++)
		{
			String []s = br.readLine().split("\\s");
			int length = s[0].length();
			min = Integer.parseInt(s[0]);
			max = Integer.parseInt(s[1]);
			if(max<10)
			{
				System.out.println("Case #" + i + ": " + 0);
				continue;
			}
		    
			int number = 0;
			
			int multiple_base = 1;
			for(int j = 1;j<length;j++)
				multiple_base*=10;
			for(int k = min;k<max;k++)
			{
				int multiple_increase = 1;
				int multiple_decrease = multiple_base;
				for(int j = 1;j<=length-1;j++)
				{
					multiple_increase*=10;
					int new_number = (k/multiple_increase) + (k%multiple_increase)*multiple_decrease;
					if(new_number>k&&new_number<=max)
						number++;
					multiple_decrease/=10;
				}
			}
			System.out.println("Case #" + i + ": " + number);
			
		}
	}
}
