package fixjava;

public class StringUtils {

	/** Repeat the given string the requested number of times. */
	public static String repeat(String str, int numTimes) {
		StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
		for (int i = 0; i < numTimes; i++)
			buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padLeft(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(padChar);
		for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
			buf.append(padChar);
		buf.append(str);
		return buf.toString();
	}

	/**
	 * Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
	 * greater than numPlaces-1, then the output string will be longer than numPlaces.
	 */
	public static String padRight(String str, char padChar, int numPlaces) {
		int bufSize = Math.max(numPlaces, str.length() + 1);
		StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
		buf.append(str);
		buf.append(padChar);
		while (buf.length() < bufSize)
			buf.append(padChar);
		return buf.toString();
	}

	/** Intern all strings in an array, skipping null elements. */
	public static String[] intern(String[] arr) {
		for (int i = 0; i < arr.length; i++)
			arr[i] = arr[i].intern();
		return arr;
	}

	/** Intern a string, ignoring null */
	public static String intern(String str) {
		return str == null ? null : str.intern();
	}

}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Qualifier2012.c;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 *
 * @author Ant Ongun Kefeli
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws FileNotFoundException, IOException {
        FileInputStream fis = new FileInputStream("src\\Qualifier2012\\c\\C-large.in");
        Scanner sc = new Scanner(fis);

        FileWriter fw = new FileWriter("src\\Qualifier2012\\c\\output.out");
        BufferedWriter out = new BufferedWriter(fw);

        int caseCount = 0;
        caseCount = sc.nextInt();
        for (int i = 0; i < caseCount; i++) {
            long smallLimit = sc.nextLong();
            long bigLimit = sc.nextLong();

            doit(out, i + 1, smallLimit, bigLimit);

        }

        out.close();
        sc.close();
    }

    private static void doit(BufferedWriter out, int casec, long smallLimit, long bigLimit) throws IOException {

        long res = 0;
        if (bigLimit < 21) {
            res = 0;
        } else {
            int digits = (int) Math.log10(smallLimit) + 1;
            Map<Long, List<Long>> map = new HashMap();
            for (long i = smallLimit; i <= bigLimit; i++) {
                for (int j = 1; j <= digits - 1; j++) {
                    String str = Long.toString(i);
                    StringBuilder sb = new StringBuilder();
                    sb.append(str.substring(str.length() - j, str.length()));
                    sb.append(str.substring(0, str.length() - j));

                    long cr = Long.parseLong(sb.toString());
                    if (cr >= smallLimit && cr <= bigLimit) {

                        long sm = i;
                        long big = cr;
                        if (i == cr) {
                            continue;
                        }
                        if (cr < i) {
                            sm = cr;
                            big = i;
                        }
                        if (map.containsKey(sm) && map.get(sm).contains(big)) {
                            continue;
                        }
                        if (map.get(sm) == null) {
                            List<Long> list = new ArrayList<Long>();
                            list.add(big);
                            map.put(sm, list);
                        } else {
                            List<Long> list = map.get(sm);
                            list.add(big);
                            map.put(sm, list);
                        }
                        res++;
                    }
                }
            }
        }
        out.write(
                "Case #" + casec + ": " + res + "\n");

    }
}
