import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

// Recycled Numbers
// https://code.google.com/codejam/contest/1460488/dashboard#s=p2

public class C {

	private static String process(Scanner in) {
		int A = in.nextInt();
		int B = in.nextInt();
		int res = 0;
		int len = Integer.toString(A).length();
		for(int n = A; n < B; n++) {
			String str = Integer.toString(n);
			TreeSet<Integer> set = new TreeSet<Integer>();
			for(int i = 1; i < len; i++) {
				int m = Integer.parseInt(str.substring(i, len) + str.substring(0, i));
				if ( m > n && m <= B && ! set.contains(m) ) {
					set.add(m);
					res++;
				}
			}
		}
		return Integer.toString(res);
	}

	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in.available() > 0 ? System.in : 
			new FileInputStream(Thread.currentThread().getStackTrace()[1].getClassName() + ".practice.in"));
		int T = in.nextInt();
		for(int i = 1; i <= T; i++) 
			System.out.format("Case #%d: %s\n", i, process(in));
	}
}

import java.util.*;
import java.io.*;

public class Recycle
{
  public static boolean sameNumbers(int n, int m, int length, int i)
  {
    
    char[] nArray = (n + "").toCharArray();
    char[] mArray = (m + "").toCharArray();
    for (int j = 0; j < length; j++)
    {
      //System.out.println(j + " " + i + " " + m + " " + mArray.length);
      if (Arrays.binarySearch(nArray, mArray[i]) == -1) return false;
      
    }

    return true;
  }
  public static boolean check(int n, int m, int a, int b, int i)
  {

    if (n > m) return false;
    else if (n == m) return false;
    else if (n < a) return false;
    else if (m > b) return false;
   // else if (!sameNumbers(n,m,(n + "").length(), i)) return false;
    // System.out.println(n + " " + m);
    return true;
  }
  public static void main (String []args) throws IOException
  {
    final String INPUT_FILE = "C-small-attempt0.in";
    final String OUTPUT_FILE = "out3.out";
    
    BufferedReader input = new BufferedReader(new FileReader(INPUT_FILE));
    PrintWriter out = new PrintWriter(new FileWriter(OUTPUT_FILE));
    
    int repeats = Integer.parseInt(input.readLine());
    
    for (int j = 0; j < repeats; j++)
    {
      StringTokenizer g = new StringTokenizer(input.readLine());  
      
      int count = 0;
      int a = Integer.parseInt(g.nextToken());
      int b = Integer.parseInt(g.nextToken());
      int aLength =  (a + "").length();
      if (aLength == 1) out.println("Case #" + (j + 1) + ": 0");
      else 
      {
        int arrayCounter = 0;
        for (int k = a; k < b; k++)
        {
          for (int i = 1; i < aLength;i++)
          {
            String kString =  k + "";
            
            //System.out.println(a + " " + aLength + " " + i);
            
            String mString1 = kString.substring(i,aLength);
            String mString2 = kString.substring(0,i);
            
            //System.out.println(kString + " " + mString1 + " " + mString2);
            
            int m = Integer.parseInt(mString1 + mString2);
            
            if (check(k,m,a,b,i))
            {
              count++;
            }
          }
        }
        out.println("Case #" + (j + 1) + ": " + count);
      }
    }
    out.close();
    input.close();
  }
}