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

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import javax.swing.JFileChooser;

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

    static Numbers[] TestCases;

    public static void main(String args[]) {
        readFile();
        for (int i = 0; i < TestCases.length; i++) {
            TestCases[i].Calculate();
        }
        WriteToFile();
    }

    private static void readFile() {
        try {
            JFileChooser FC = new JFileChooser();
            String Path = null;
            if (FC.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                Path = FC.getSelectedFile().getPath();

                StringBuffer Text = new StringBuffer();
                FileInputStream FIS = null;
                DataInputStream DIS;
                BufferedReader BR;

                FIS = new FileInputStream(Path);
                DIS = new DataInputStream(FIS);
                BR = new BufferedReader(new InputStreamReader(DIS));
                int TestCasesCount = Integer.valueOf(BR.readLine());

                TestCases = new Numbers[TestCasesCount];
                for (int i = 0; i < TestCasesCount; i++) {
                    String[] AB = BR.readLine().split(" ");
                    TestCases[i] = new Numbers(Integer.valueOf(AB[0]), Integer.valueOf(AB[1]));
                }
                FIS.close();
                DIS.close();
                BR.close();

            }
        } catch (IOException ex) {
            System.out.println(ex.getMessage());
        }
    }

    private static void WriteToFile() {
        FileOutputStream FOS = null;
        DataOutputStream DOS;
        BufferedWriter BW;
        try {
            FOS = new FileOutputStream(new File("Recycled"));
        } catch (FileNotFoundException ex) {
        }
        DOS = new DataOutputStream(FOS);
        BW = new BufferedWriter(new OutputStreamWriter(DOS));

        for (int i = 0; i < TestCases.length; i++) {
            String Line = "Case #" + (i + 1) + ": " + TestCases[i].Result+"\n";
            try {
                BW.write(Line);
            } catch (IOException ex) {
                System.err.println(ex.getMessage());
            }
        }
        try {
            BW.close();
        } catch (IOException ex) {
            System.err.println(ex.getMessage());
        }

    }
}
