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();
	}

}

package com.irabin.google.codejam.problem3;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class RecycledNumber {

	private Scanner scanner;
	private PrintWriter writer;

	public RecycledNumber(InputStream in, OutputStream os) {
		scanner = new Scanner(in);
		writer = new PrintWriter(os);
	}

	public void solve() {

		int n = Integer.parseInt(scanner.nextLine());

		for (int i = 1; i <= n; i++) {
			writer.print("Case #" + i + ": ");

			String output = "";

			Long A = scanner.nextLong();
			Long B = scanner.nextLong();

			int total = 0;
			for (Long j = A; j <= B; j++) {

				String str = String.valueOf(j);
				if (str.length() < 2) {
					continue;
				}

				int startIndex = 1;
				int endIndex = str.length();
				while (startIndex < endIndex) {
					String notSubStr = str.substring(0, startIndex);
					String substr = str.substring(startIndex);

					String newValue = substr.concat(notSubStr);
					Long C = Long.valueOf(newValue);
					
					String strJ = String.valueOf(j);
					String strC = String.valueOf(C);

					if (A<=j && j < C && C <= B && strJ.length()==strC.length()) {
						total = total + 1;
					}

					startIndex = startIndex + 1;
				}

			}
			output = String.valueOf(total);

			writer.println(output);
			writer.flush();
		}
		writer.close();

	}

	public static void main(String args[]) {

		InputStream input = null;
		input = RecycledNumber.class.getResourceAsStream(args[0]);

		OutputStream output = null;
		try {
			output = new FileOutputStream(args[1]);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		RecycledNumber practise1 = new RecycledNumber(input, output);
		practise1.solve();
	}
}
