import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Scanner;

public class GCJ12QRC
{
	private static int a, b, d;
	private static long c;
	private static String output, newline = System.getProperty("line.separator");

	public static void fun()
	{
		String s;
		int i, j, k;
		c = d = 0;
		for(i=a; i>0; i/=10)
			d++;

		for(i=a; i<b; i++) {
			s = "" + i;
			for(j=1; j<d; j++) {
				k = Integer.parseInt(s.substring(j) + s.substring(0, j));
				if(k>i && k<=b) {
					c++;
				}
			}
		}
	}

	public static void main(String[] args) throws IOException
	{
		long t2, t1 = System.currentTimeMillis();
		output = "";
		Scanner sc = new Scanner(new File("C-large.in"));
		int ntc = sc.nextInt();

		for(int w=1; w<=ntc; w++)
		{
			a = sc.nextInt();
			b = sc.nextInt();
			fun();
			output += "Case #" + w + ": " + c + newline;
		}
		sc.close();

		OutputStream fo = new FileOutputStream("C-large.out");
		fo.write(output.getBytes());
		fo.close();
		t2 = System.currentTimeMillis();
		System.out.println( "Time in millis : " + (t2-t1) );
	}
}
