import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

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++;
        }
    }
}
