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

			}
		}

	}
}

import java.util.Scanner;

public class QualC
{
	public static void main(String args[])
	{
		Scanner kb = new Scanner(System.in);
		int ntc = kb.nextInt();
		
		for(int tc=0;tc<ntc;tc++)
		{
			int out = 0;
			int a = kb.nextInt();
			int b = kb.nextInt();
			
			for(int n=a;n<b;n++)
			{
				int temp = n;
				int nn = 0;
				while(temp>0)
				{
					nn++;
					temp/=10;
				}
				
				int chk[] = new int[nn];
				for(int q=1;q<nn;q++)
				{
					int f = 0;
					int m = n%((int)Math.pow(10,nn-q)) * (int)Math.pow(10,q) + n/((int)Math.pow(10,nn-q));
					chk[q] = m;
					for(int z=1;z<q;z++)
					{
						if(m == chk[z])
						{
							f = 1;
							break;
						}
					}
					if(n<m && m>=a && m<=b && m/(int)Math.pow(10,nn-1)>0 && f==0)
					{
						out++;
					}
				}
			}
			
			System.out.println("Case #" + (tc+1) + ": " + out);
		}
	}
}
