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.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class QrC {
	private CodeJamTextInputReader input = null;
	private CodeJamTextOutputWriter output = null;

	public static void main(String args[]) {
		// CodeJamUtils.initLineEndings();
		try {
			QrC qrA = new QrC();
			qrA.run(new File(args[0]), new File(args[1]));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvalidInputException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public QrC() {
	}

	public void run(File outputFile, File inputFile)
			throws InvalidInputException, IOException {
		try {
			input = new CodeJamTextInputReader(inputFile);
			output = new CodeJamTextOutputWriter(outputFile);

			actualRun();
		} finally {
			if (input != null) {
				input.close();
			}
			if (output != null) {
				output.close();
			}
		}
	}

	private void actualRun() throws IOException {
		while (input.hasNextTestCase()) {
			String in = input.readNextLine();
			final int textCaseNum = input.getLastReadTestCaseNumber();

			output.outputTestCase(textCaseNum, singleTestCase(in));
		}
	}

	private String singleTestCase(String in) {
		CodeJamLineParser parser = new CodeJamLineParser(in);
		final int lowerBound = parser.readNextInt();
		final int upperBound = parser.readNextInt();

		int numOfRecycled = 0;

		Set<RecycledPair> alreadyHit = new HashSet<RecycledPair>();

		RecycledPair comparePair = new RecycledPair();
		
		for (int i = lowerBound; i <= upperBound; ++i) {
			int leftMask = getHighestMask(i);
			int rightMask = 10;
			while (leftMask >= 10) {
				int recycled = buildRecycled(i, leftMask, rightMask);
				comparePair.set(i, recycled);
				if (recycled != i && recycled >= lowerBound
						&& recycled <= upperBound
						&& !alreadyHit.contains(comparePair)) {
					alreadyHit.add(new RecycledPair(comparePair));
					++numOfRecycled;
				}
				rightMask = rightMask * 10;
				leftMask = leftMask / 10;
			}
		}

		return Integer.toString(numOfRecycled);
	}

	int buildRecycled(int in, int leftMask, int rightMask) {
		int rightPart = in % rightMask;
		int leftPart = in / rightMask;

		return (rightPart * leftMask) + leftPart;
	}

	int getHighestMask(int in) {
		int mask = 10;
		while (in / mask != 0) {
			mask = mask * 10;
		}
		return mask / 10;
	}

	int getNumOfDigits(int in) {
		int numOfDigits = 1;
		int mask = 10;
		while (in / mask != 0) {
			++numOfDigits;
			mask = mask * 10;
		}
		return numOfDigits;
	}
}
