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

import java.awt.Container;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JTextArea;


public class Recycling extends JFrame
{
	private final int WIDTH = 800;
	private final int HEIGHT = 400;
	private Container pane; 
	
	private int[] A;
	private int[] B;
	private int[] numberOfSolutions;
	
	private String[][] permutations;
	
	private int numberOfLines;
	private int lastI = 0;
	private int lastWorkingOnIt = 0;
	
	
	private JTextArea input, output;
	
	
	private Scanner scanner;
	private PrintWriter out, outDebug;
	
	
	public Recycling() throws IOException
	{
		pane = new Container();
		pane = getContentPane();
		
		scanner = new Scanner(new File("c:/users/Christopher/Desktop/input.in"));
		out = new PrintWriter(new FileWriter("c:/users/Christopher/Desktop/output.out")); 
		outDebug = new PrintWriter(new FileWriter("c:/users/Christopher/Desktop/debug.out")); 
		
		numberOfLines = Integer.parseInt(scanner.nextLine());
		
		A = new int[numberOfLines];
		B = new int[numberOfLines];
		numberOfSolutions = new int[numberOfLines];
		
		
		
		input = new JTextArea(100, numberOfLines);
		input.setSize(300,200);
		input.setLocation (10, 10);
		
		output = new JTextArea(120, numberOfLines);
		output.setSize(300,200);
		output.setLocation(410, 10);
		
		pane.setLayout(null);
		pane.add(input);
		pane.add(output);
		
		
		
		for (int i = 0; i < numberOfLines; i++)
		{
			A[i] = scanner.nextInt();
			B[i] = scanner.nextInt();
			
			numberOfSolutions[i] = findSolutions(i);
			
			input.append(A[i] + " " + B[i] + "\n");
			output.append("Case #" + (i + 1) + ": " + numberOfSolutions[i] + "\n");
			out.println("Case #" + (i + 1) + ": " + numberOfSolutions[i]);
		}
		
		
		
		
		
		scanner.close();
		out.close();
		outDebug.close();
		
		setVisible(true);
		setSize(WIDTH, HEIGHT);
		setTitle("Recycling");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		
	}
	
	public static void main(String args[]) throws IOException
	{
		Recycling awesome = new Recycling();
	}
	
	
	
	int findSolutions(int whichLine)
	{
		int difference = B[whichLine] - A[whichLine] + 1;
		permutations = new String[difference][];
		int workingOnIt;
		
		int numberOfDigits;
		int whichEntry;
		
		for (int i = A[whichLine]; i < B[whichLine] + 1; i++)
		{
			whichEntry = i - A[whichLine];
			numberOfDigits = (int)Math.floor(Math.log10((double)i)) + 1;
			permutations[i - (A[whichLine])] = new String[numberOfDigits];
			
			for (int j = 0; j < numberOfDigits; j++)
			{
				
				permutations[whichEntry][j] = rotator(Integer.toString(i), j);
				
				workingOnIt = Integer.parseInt(permutations[whichEntry][j]);
				
				if (workingOnIt > i && workingOnIt <= B[whichLine] && permutations[whichEntry][j].charAt(0) != '0' && (i != lastI || workingOnIt != lastWorkingOnIt))
				{
					numberOfSolutions[whichLine]++;
					lastI = i;
					lastWorkingOnIt = workingOnIt;
				}
			}
		}
		
		return numberOfSolutions[whichLine];
	}
	
	
	
	
	String rotator(String original, int numberOfTimes)
	{
		char[] originalChar = original.toCharArray();
		
		char temp; 
		
		for (int i = 0; i < numberOfTimes; i++)
		{
			temp = originalChar[0];
			
			for (int j = 1; j < originalChar.length; j++)
			{
				originalChar[j - 1] = originalChar[j];
			}
			
			originalChar[originalChar.length - 1] = temp;
		}
		
		String rotatedString = new String(originalChar);
		
		return rotatedString;
	}
}