import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

public class Recycled {
	public static void main(String[] args) throws Exception{
		String inputFile = "C-small-attempt0.in";
		
		BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile)));
		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output")));
		long num_cases = Long.parseLong(input.readLine());
		int current_case = 0;
		
		while (current_case < num_cases){
			current_case++;
			
			String[] fields = input.readLine().split(" ");
			int A = Integer.parseInt(fields[0]);
			int B = Integer.parseInt(fields[1]);
			int total = 0;
			
			for (int n = A; n < B; n++){
				for (int m = n+1; m <= B; m++){
					if (isRecycled(n,m)) total++;
				}
			}
			
			System.out.println("Case #" + current_case + ": " + total);
			output.write("Case #" + current_case + ": " + total + "\n");
		}
		output.close();
	}

	private static boolean isRecycled(int n, int m) {
		String sn = ""+n;
		String sm = ""+m;
		if (sn.length() != sm.length()) return false;
		int totaln = 0, totalm = 0;
		for (int i = 0; i < sn.length(); i++){
			totaln += sn.charAt(i);
			totalm += sm.charAt(i);
		}
		if (totaln != totalm) return false;
		for (int i = 0; i < sn.length()-1; i++){
			sm = sm.charAt(sm.length() - 1) + sm.substring(0, sm.length() - 1);
			if (sm.equals(sn)) return true;
		}
		return false;
	}
}

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googlecodejam;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * @author Wouter
 */
public class RecycledNumbers {

    ArrayList<String> cases = new ArrayList<String>();

    public RecycledNumbers() {


        try {
            // Setup in/out
            System.setIn(new FileInputStream("C:\\GCJ\\C-small-attempt0.in"));
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\GCJ\\C-small-attempt0.out"));
            bw.flush();



            int untill = Integer.parseInt(br.readLine());

            for (int x = 1; x <= untill; x++) {
                int ans = 0;
                String[] s = br.readLine().split(" ");
                int a = Integer.parseInt(s[0]);
                int b = Integer.parseInt(s[1]);

                for (int z = a; z <= b; z++) {
                    List<Integer> ints = getAllRecycledPairsOf(z);
                    removeDups(ints);
                    Collections.sort(ints);

                    for (Integer nr : ints) {
                        if (between(nr, a, b)) {
                            ans++;
                        } else if (nr > b) {
                            break;
                        }
                    }
                }

                String out = "Case #" + x + ": " + ans;

                cases.add(out);

            }

            for (String s : cases) {
                System.out.println(s);
                bw.write(s);
                bw.flush();
                bw.newLine();
            }

        } catch (IOException ex) {
            System.out.println("SOMETHING WENT WRONG");
        }

    }

    public List<Integer> getAllRecycledPairsOf(int nr) {
        List<Integer> ints = new ArrayList<Integer>();

        StringBuilder s = new StringBuilder();
        s.append(nr);

        String start = s.toString();

        for (int x = 1; x < start.length(); x++) {
            s = new StringBuilder();
            String back = start.substring(start.length() - x, start.length());
            String front = start.substring(0, start.length() - x);
            s.append(back).append(front);
            if (!back.startsWith("0")) {
                Integer newNr = new Integer(s.toString());
                if (newNr > nr) {
                    ints.add(newNr);
                }
            }
        }

        return ints;
    }

    public static void main(String[] args) {
        RecycledNumbers test = new RecycledNumbers();
    }

    public boolean between(int nr, int a, int b) {
        if (nr >= a && nr <= b) {
            //System.out.println(nr);
            return true;
        }
        return false;
    }

    public static void removeDups(List<Integer> list) {
        Set<Integer> s = new HashSet<Integer>(list);
        list.clear();
        list.addAll(s);
    }
}
