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

			}
		}

	}
}

package fixjava;

/** Adapted from http://www.johndcook.com/standard_deviation.html */
public class RunningStats {

	int n = 0;
	double oldM, newM, oldS, newS, min, max;

	public void clear() {
		n = 0;
	}

	public void add(double x) {
		n++;

		// See Knuth TAOCP vol 2, 3rd edition, page 232
		if (n == 1) {
			oldM = newM = min = max = x;
			oldS = 0.0;
		} else {
			newM = oldM + (x - oldM) / n;
			newS = oldS + (x - oldM) * (x - newM);
			min = Math.min(min, x);
			max = Math.max(max, x);
			
			// set up for next iteration
			oldM = newM;
			oldS = newS;
		}
	}

	public int numValues() {
		return n;
	}

	public double mean() {
		return (n > 0) ? newM : 0.0;
	}

	public double variance() {
		return ((n > 1) ? newS / (n - 1) : 0.0);
	}

	public double stdDev() {
		return Math.sqrt(variance());
	}
	
	public double min() {
		return (n > 0) ? min : 0.0;
	}
	
	public double max() {
		return (n > 0) ? max : 0.0;
	}
}
