import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String line = bf.readLine();
			int T = Integer.parseInt(line);
			for (int testcaseIndex=0; testcaseIndex<T; testcaseIndex++) {

				String testCase = bf.readLine();
				String[] array = testCase.split(" ");
				int A = Integer.parseInt(array[0]);
				int B = Integer.parseInt(array[1]);
						
				int out  = main.solve(A,B);
				
				System.out.print("Case #"+(testcaseIndex+1)+": ");
				System.out.println(out);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int solve(int A, int B) {
		HashSet<Pair> set = new HashSet<Pair>();		
		for (int num=A; num<=B; num++) {
			String numStr = String.valueOf(num);
			for (int i=1; i<numStr.length(); i++) {
				String tempStr = numStr.substring(i) + numStr.substring(0,i);
				int temp = Integer.valueOf(tempStr);
				if ( A <= temp && temp <= B && num != temp) {
					set.add(new Pair(num, temp));
				}
			}
		}
		return set.size();
	}

	private class Pair {
		int small;
		int large;
		
		Pair(int s, int l) {
			if (s > l) {
				int t = s;
				s = l;
				l = t;
			}
			small = s;
			large = l;
		}
		
		@Override
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair pair = (Pair)o;
				return this.small == pair.small && this.large == pair.large;
			}
			return false;
		}
		
		@Override
		public int hashCode() {
			return small * 23 + large;
		}
	}
	
	
}
