package codejam;

import java.util.*;
import java.io.*;

public class RecycledNumbers {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader("in.txt"));
		PrintWriter out = new PrintWriter(new File("out.txt"));
		
		int T = Integer.parseInt(in.readLine());
		for (int t = 1; t <= T; ++t) {
			String[] parts = in.readLine().split("[ ]+");
			int A = Integer.parseInt(parts[0]);
			int B = Integer.parseInt(parts[1]);
			
			int cnt = 0;
			for (int i = A; i < B; ++i) {
				String str = String.valueOf(i);
				int n = str.length();
				String res = "";
				Set<Integer> seen = new HashSet<Integer>();
				for (int j = n - 1; j > 0; --j) {
					res = str.substring(j) + str.substring(0, j);
					int k = Integer.parseInt(res);
					if (k > i && k <= B) {
						//System.out.println("(" + i + ", " + k + ")");
						if (!seen.contains(k)) {
							++cnt;
							seen.add(k);
						}
					}
				}
			}

			out.println("Case #" + t + ": " + cnt);
		}
		
		in.close();
		out.close();
		System.exit(0);
	}
}

package student;

import java.io.*;
import java.util.*;

public class test {
	
	public static int getShift(String t, int pos)
	{
		int len = t.length()/2;
		return Integer.parseInt(t.substring(pos,pos+len));
	}
	
	public static void main(String[] args) throws FileNotFoundException
	{
		
		Scanner fin = new Scanner(new File("a.txt"));
		int ncase = fin.nextInt();
		
		int a=0,b=0;
		
		for(int cc = 1; cc<=ncase;cc++)
		{
			a= fin.nextInt();
			b= fin.nextInt();
			HashSet<Pair> set = new HashSet<Pair>();
			for(int i=a;i<=b;i++)
			{
				String t = (""+i) + (""+i);
				int len = t.length()/2;
				for(int j=1;j<len;j++)
				{
					int p = getShift(t, j);
					if(p>=a&&p<=b&&(""+p).length()==len && p!=i)
						set.add(new Pair(i,p));
				}
			}
			System.out.println("Case #" + cc + ": " + set.size()/2);
		}
			
	}
}
class Pair
{
	public int a,b;
	public Pair(int x,int y)
	{
		a=x;b=y;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + a;
		result = prime * result + b;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pair other = (Pair) obj;
		if (a != other.a)
			return false;
		if (b != other.b)
			return false;
		return true;
	}
}
