import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class CopyOfCopyOfMain {

	static int ndigits(int n) {
		return (int) (Math.log10(n) + 1);
	}

	static int rot(int n, int dig) {
		return (int) ((n % 10) * Math.pow(10, dig - 1)) + (int) (n / 10);
	}

	public static void main(String[] args) throws FileNotFoundException {
		String file = "C-large";
		Scanner in = new Scanner(new File(file + ".in"));
		PrintWriter out = new PrintWriter(new File(file + ".out"));

		int T = in.nextInt();
		for (int t = 1; t <= T; t++) {
			int A = in.nextInt();
			int B = in.nextInt();

			int c = 0;
			int[] list = new int[ndigits(B)];
			numbers: for (int i = A; i <= B; i++) {
				int digs = ndigits(i);
				int rot = i;
				int pairs = 0;

				Arrays.fill(list, -1);
				list[0] = i;

				digits: for (int j = 1; j <= digs + 1; j++) {

					rot = rot(rot, digs);
					if(rot < i)
						continue;

					if (A <= rot && rot <= B) {
						for (int k = 0; k < j; k++) {
							if (list[k] == rot) {
								continue digits;
							}
						}
						pairs++;
						list[j] = rot;
					}
				}

				//c += pairs * (pairs + 1) / 2;
				c += pairs ;
				// c+=digs;
			}
			out.println("Case #" + t + ": " + c);
		}

		in.close();
		out.close();
	}
}

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class RecycledNumbers {

    public static int recycle(int source, int digits) {
        int pow = (int) Math.pow(10, digits - 1);
        int mod = source % 10;
        return pow * mod + source / 10;
    }

    public static class Range {
        public final int A;
        public final int B;

        public Range(int A, int B) {
            this.A = A;
            this.B = B;
        }
    }

    public static Iterator<Range> iterator(Readable input) {
        final Scanner scanner = new Scanner(input);

        return new Iterator<Range>() {
            private int cases = scanner.nextInt();

            @Override
            public boolean hasNext() {
                return cases > 0;
            }

            @Override
            public Range next() {
                int A = scanner.nextInt();
                int B = scanner.nextInt();

                cases--;
                return new Range(A, B);
            }

            @Override
            public void remove() {
                throw new AbstractMethodError();
            }
        };
    }

    public static int recycledPairs(Range scores) {
        int digits = Integer.toString(scores.A).length();
        HashSet<String> pairs = new HashSet<String>();
        for (int i = scores.A; i <= scores.B; i++) {
            int recycled = recycle(i, digits);
            while (recycled != i) {
                if (recycled >= scores.A && recycled <= scores.B) {
                    int first = i < recycled ? i : recycled;
                    int second = i > recycled ? i : recycled;

                    pairs.add(String.format("%d%d", first, second));
                }
                recycled = recycle(recycled, digits);
            }
        }

        return pairs.size();
    }

    public static void main(String[] args) throws FileNotFoundException {
        FileReader fileReader = new FileReader(args[0]);

        int caseId = 1;
        Iterator<Range> iterator = iterator(fileReader);

        while (iterator.hasNext()) {
            int result = recycledPairs(iterator.next());
            System.out.format("Case #%s: %s\n", caseId, result);
            caseId++;
        }
    }
}
