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 blacky.codejam.qualifications;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class RecycledNumbers {

	private static class Pair {
		
		final public int m;
		
		final public int n;
		
		public Pair(int m, int n) {
			this.m = m;
			this.n = n;
		}
		
		public boolean equals(Object other) {
			return ((Pair)other).m == this.m && ((Pair)other).n == this.n;
		}
		
		public String toString() {
			return String.format("(%d,%d)", this.m, this.n);
		}
		
		public int hashCode() {
			return this.m * 31 + n;
		}
		
	}
	
	public static void main(String args[]) throws Exception {
		BufferedReader reader = new BufferedReader(new FileReader(new File(args[0])));
		int numberOfTestCases = Integer.parseInt(reader.readLine());
		for(int i = 0; i < numberOfTestCases; i++) {
			String numbers[] = reader.readLine().split(" ");
			Set<Pair> pairs = new HashSet<Pair>();
			int a = Integer.parseInt(numbers[0]);
			int b = Integer.parseInt(numbers[1]);
			for(int j = a; j < b; j++) {
				String jAsString = Integer.toString(j);
				int recycledNumbers[] = new int[jAsString.length()];
				recycledNumbers[0] = j;
				for(int k = 1; k < jAsString.length(); k++) {
					int offset = jAsString.length() - k;
					String currentRecNum = jAsString.substring(offset).concat(jAsString.substring(0, offset));
					recycledNumbers[k] = Integer.parseInt(currentRecNum);
				}
				Arrays.sort(recycledNumbers);
				for(int k = 0; k < recycledNumbers.length - 1; k++) {
					if(!(a <= recycledNumbers[k] && recycledNumbers[k] <= b)) continue;
					for(int l = k + 1; l < recycledNumbers.length; l++) {
						if(!(a <= recycledNumbers[l] && recycledNumbers[l] <= b)) continue;
						if(recycledNumbers[l] == recycledNumbers[k]) continue;
						pairs.add(new Pair(recycledNumbers[k], recycledNumbers[l]));
					}
				}
			}
			System.out.println(String.format("Case #%d: %d", i + 1, pairs.size()));
		}
	}
	
}
