package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

import java.util.HashSet;
import java.util.Set;


public class TestCase {

	private int totalDigit = -1;
	private int max;
	private int min;
	public TestCase(String s) {
		String[] results = s.split(" ");
		totalDigit = results[0].length();
		min = Integer.parseInt(results[0]);
		max = Integer.parseInt(results[1]);
	}
	
	public int solve() {
		Set<Pair> total = new HashSet<Pair>();
		for (int i = min; i <= max; i++) {
			for (int j = 1; j < totalDigit; j++) {
				Pair p = getPair(i, j);
				if (p != null) {
					//System.out.printf("Adding pair(%d, %d), %b\n", p.getFirst(), p.getSecond(), total.add(p));
					total.add(p);
				}
			}
		}
		return total.size();
		
	}

	private Pair getPair(int number, int digit) {
		String source = String.valueOf(number);
		String target;
		Pair result = null;
		String first;
		String second;
//		if (digit == 1) {
//			first = source.substring(totalDigit - digit);
//			second = source.substring(0, digit);
////			target = source.substring(0, totalDigit) + source.substring(totalDigit - digit);
//		} else if (digit == 2) {
			first = source.substring(totalDigit - digit);
			second = source.substring(0, totalDigit - digit);
//		}
		target =  first + second;
		int targetNumber = Integer.parseInt(target);
		if (targetNumber >= min && targetNumber <= max & targetNumber != number) {
			result = new Pair(number, targetNumber);
		}
		return result;
	}
}
