import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package com.renoux.gael.codejam.utils;

import java.io.Closeable;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


public class Output implements Closeable {

    private static String lineSeparator = System.getProperty("line.separator");

    private FileWriter writer;


    private Output(File file) {
        try {
            writer = new FileWriter(file);
        } catch (IOException e) {
            throw new TechnicalException(e);
        }
    }

    public static Output open(File file) {
        System.out.println("======== " + file);
        return new Output(file);
    }

    public void writeLine(String text) {
        System.out.println(text);
        try {
            writer.write(text);
            writer.write(lineSeparator);
        } catch (IOException e) {
            throw new TechnicalException(e);
        }
    }

    public void write(String text) {
        System.out.print(text);
        try {
            writer.write(text);
        } catch (IOException e) {
            throw new TechnicalException(e);
        }
    }

    public void writeLine(Object... text) {
        try {
            for (Object s : text) {
                System.out.print(s);
                writer.write(s.toString());
            }
            System.out.println();
            writer.write(lineSeparator);
        } catch (IOException e) {
            throw new TechnicalException(e);
        }
    }

    public void write(Object... text) {
        try {
            for (Object s : text) {
                System.out.print(s);
                writer.write(s.toString());
            }
        } catch (IOException e) {
            throw new TechnicalException(e);
        }
    }

    public void close() {
        System.out.println("================ closed");
        try {
            writer.close();
        } catch (IOException e) {
            throw new TechnicalException(e);
        }
    }

}
