import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class CopyOfCopyOfMain {

	static int ndigits(int n) {
		return (int) (Math.log10(n) + 1);
	}

	static int rot(int n, int dig) {
		return (int) ((n % 10) * Math.pow(10, dig - 1)) + (int) (n / 10);
	}

	public static void main(String[] args) throws FileNotFoundException {
		String file = "C-large";
		Scanner in = new Scanner(new File(file + ".in"));
		PrintWriter out = new PrintWriter(new File(file + ".out"));

		int T = in.nextInt();
		for (int t = 1; t <= T; t++) {
			int A = in.nextInt();
			int B = in.nextInt();

			int c = 0;
			int[] list = new int[ndigits(B)];
			numbers: for (int i = A; i <= B; i++) {
				int digs = ndigits(i);
				int rot = i;
				int pairs = 0;

				Arrays.fill(list, -1);
				list[0] = i;

				digits: for (int j = 1; j <= digs + 1; j++) {

					rot = rot(rot, digs);
					if(rot < i)
						continue;

					if (A <= rot && rot <= B) {
						for (int k = 0; k < j; k++) {
							if (list[k] == rot) {
								continue digits;
							}
						}
						pairs++;
						list[j] = rot;
					}
				}

				//c += pairs * (pairs + 1) / 2;
				c += pairs ;
				// c+=digs;
			}
			out.println("Case #" + t + ": " + c);
		}

		in.close();
		out.close();
	}
}

import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.Integer;
import java.io.*;
import java.util.Scanner;

public class RecycledNumbers{

  private long inversions = 0;
  
  public static void main(String[] args) throws FileNotFoundException{
    String filename = args[0];
    RecycledNumbers countInversions = new RecycledNumbers();
    countInversions.readArray(filename);
//    list = countInversions.sortAndCount(list);
//    System.out.println(list);
//    System.out.println(countInversions.inversions);
  }
  
  private void readArray( String filename ) throws FileNotFoundException{
    ArrayList<Integer> list = new ArrayList<Integer>();
    File fFile = new File(filename);
    Scanner scanner = new Scanner(new FileReader(fFile));
    try {
      BufferedWriter out = new BufferedWriter(new FileWriter("outfilename"));
      int k = Integer.valueOf(scanner.nextLine());
      for (int j=1; j<=k; ++j){
        String szoveg = scanner.nextLine();
        Object[] szamok =szoveg.split("[^0-9]");
        int A = Integer.valueOf((String)szamok[0]);
        int B = Integer.valueOf((String)szamok[1]);

        String mashogy = new String();

        mashogy = mashogy.concat("Case #");
        mashogy = mashogy.concat(((Integer)j).toString());
        mashogy = mashogy.concat(": ");


        int s=0;
        for (int i=A; i<B; ++i){
          int l = ((Integer)A).toString().length();
//          System.out.println(l);
          ArrayList<Integer> elerh = new ArrayList<Integer>();
          for (int f=1; f<l; ++f){
            int pow = (int)Math.floor(Math.pow(10,f));
            int powpot = (int)Math.floor(Math.pow(10,l-f));
            int ael = i/pow;
            int aveg = i%pow;
            int ford = powpot*aveg+ael;
            if (ford>i && ford<=B && !elerh.contains(ford)){
//              System.out.println(pow+" "+ael+" "+aveg+" "+ford);
              elerh.add(ford);
              s++;
            }
          }
        }
//      String mashogy = (String)(szoveg.clone());
//      System.out.println(szoveg);
        mashogy = mashogy.concat(((Integer)s).toString());
        mashogy = mashogy.concat("\n");
        out.write(mashogy);
      }    
      out.close();
    } catch (IOException e) {
    }
    scanner.close();
    return;
  }
}
