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.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;


public class ProblemC {
	
	public int countDistinctRecycledPairsBetween(int min, int max) {
		int count = 0;
		int digit = Integer.toString(min).length();
		for (int i = min; i <= max; i++) {
			count += this.countDistinctRecycledPairOf(i, min, max, digit);
		}
		return count;
	}
	
	public int countDistinctRecycledPairOf(int number, int min, int max, int digit) {
		List<Integer> used = new ArrayList<Integer>(digit);
		int count = 0;
		int rotated = number;
		
		for (int i = 0, rotateCount = digit - 1; i < rotateCount; i++) {
			rotated = this.shiftRightAndRotate(rotated, digit);
			
			if (rotated > number && rotated <= max && used.indexOf(rotated) == -1) {
				count++;
				used.add(rotated);
			}
		}
		
		return count;
	}
	
	private int shiftRightAndRotate(int number, int digit) {
		return (number % 10) * (int)Math.pow(10, digit - 1) + (number / 10);
	}
	
	public void solve(String inputFileName, String outputFileName) {
		try {
			BufferedReader reader = new BufferedReader(new FileReader(new File(inputFileName)));
			BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName));
			
			int testCount = Integer.parseInt(reader.readLine());
			for (int i = 0; i < testCount; i++) {
				String testCase = reader.readLine();
				String[] fields = testCase.split(" ");
				
				int min = Integer.parseInt(fields[0]);
				int max = Integer.parseInt(fields[1]);
				int count = this.countDistinctRecycledPairsBetween(min, max);
				
				writer.write("Case #" + (i + 1) + ": " + count);
				writer.newLine();
			}
			
			reader.close();
			writer.close();
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage(), e);
		}
	}
	
	public static void main(String[] args) {
		ProblemC problem = new ProblemC();
//		problem.solve("C-small-attempt.in", "C-small-attempt.out");
//		problem.solve("C-small-attempt0.in", "C-small-attempt0.out");
		problem.solve("C-large.in", "C-large.out");
	}
}
