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.*;
import java.io.*;

class problemC {
	static class Coordinate implements Comparable<Coordinate> {
		int x, y;

		public Coordinate(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public boolean equal(Object o) {
			if (o == null || !(o instanceof Coordinate)) {
				return false;
			} else {
				return ((Coordinate)o).x == this.x &&
					((Coordinate)o).y == this.y;
			}
		}

		@Override
		public int compareTo(Coordinate o) {
			// TODO Auto-generated method stub
			if (o.x == this.x && o.y == this.y)
				return 0;
			else
				return -1;
		}
		
		public String toString() {
			return "(" + Integer.toString(x) + "," + Integer.toString(y) + ")";
		}
	}

	public static void main(String[] args) throws FileNotFoundException {
		String myFilename = (args.length < 1) ? "test" : args[0];
		Set<Coordinate> mySet = new TreeSet<Coordinate>();
		Scanner sc = new Scanner(new File(myFilename));
		int testCases, A, B, maxDigits, newNum;
		String currNumStr, shiftedNumStr, frontStr, newStr;

		testCases = sc.nextInt();
		sc.nextLine();

		for (int cases = 0; cases < testCases; cases++) {
			A = sc.nextInt();
			B = sc.nextInt();

			mySet.clear();
			for (int x = A; x <= B; x++) {
				currNumStr = Integer.toString(x);
				maxDigits = currNumStr.length();
				// Shifting 0 and maxDigits won't change the number
				for (int digitsToShift = 1; digitsToShift < maxDigits; digitsToShift++) {
					shiftedNumStr = currNumStr.substring(digitsToShift, currNumStr.length());
					if (shiftedNumStr.charAt(0) == '0')
						continue;
					frontStr = currNumStr.substring(0, digitsToShift);
					newStr = shiftedNumStr + frontStr;
					newNum = Integer.parseInt(newStr);
					if (x < newNum && newNum >= A && newNum <= B)
						mySet.add(new Coordinate(x, newNum));
				}
			}

			System.out.println("Case #" + (cases+1) + ": " + mySet.size());
		}
	}
}
