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.io.*;
import java.util.*;
import java.math.*;
public class Solution {
	public static void main(String args[]) throws Exception {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int t = 0; t < T; t++) {
			int A=sc.nextInt();
			int B=sc.nextInt();
			int dig=digi(A);
			int mdig=minDig(A);
			int mdig10=mdig*10;
			int curr=A;
			int count=0;
			//System.out.println(A+" "+B+" "+dig+" "+mdig+" "+mdig10+" "+curr);
			HashSet<Long> set = new HashSet<Long>(); 
			while(curr<=B) {
				int curr2=curr;
				for(int i=0;i<dig;i++) {
					int lastdig=curr2%10;
					curr2=curr2/10+lastdig*mdig;
					if(lastdig!=0&&curr<curr2&&curr2<=B) {
						long uniq=curr*200000001L+curr2;
						if(!set.contains(uniq)) {
							set.add(uniq);
							count++;
						}
					}
					//System.out.println(curr+ " "+curr2);
				}
				curr++;
				if(curr==mdig10) {
					mdig*=10;
					mdig10*=10;
					dig++;
				}
			}
			System.out.println("Case #"+(t+1)+": "+count);
		}
	}
	static int digi(int i) {
		int n=0;
		while(i>9) {
			i/=10;
			n++;
		}
		return n;
	}
	static int minDig(int i) {
		int n=1;
		while(i>9) {
			i/=10;
			n*=10;
		}
		return n;
	}
}
