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

class B
{
	public static void main(String[] args) 
	{
		try
		{
			BufferedReader br = new BufferedReader(new FileReader("B.in"));
			PrintWriter pw = new PrintWriter(new FileWriter("B.out"));
			int X = Integer.parseInt(br.readLine());

			for(int i=0; i<X; i++)
			{
				String[] S = br.readLine().split(" ");
				int A = Integer.parseInt(S[0]);
				int B = Integer.parseInt(S[1]);
				int R = 0;

				int x = 1;
				int n = 0;
				while(A/x > 0) {
					n++;
					x *= 10;
				}

				for(int j=A; j<B; j++) {
					Set<Integer> seen = new HashSet<Integer>();
					for(int k=1; k<n; k++) {
						int p1 = j % (int)Math.pow(10, k);
						int p2 = (int) Math.pow(10, n-k);
						int p3 = j / (int)Math.pow(10, k);
						int y = p1*p2 + p3;
						
						if(j < y && !seen.contains(y) && y <= B) {
							seen.add(y);
							R++;
						}
					}
				}

				pw.printf("Case #%d: %d\n", i+1, R);
				pw.flush();
			}
		}
		catch(Exception e)
		{ 
			e.printStackTrace();
		}
	}
}

package qr;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;

public class C {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner scanner = new Scanner(new File("C-large.in"));
    int tcn = scanner.nextInt();
    int tc = 1;
    while (tc <= tcn) {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      int y = 0;
      // System.out.printf("%d %d\n", a, b);
      if (a > 9) {
        y = 0;
        for (int n = a; n < b; n++) {
          String ns = Integer.toString(n);
          // System.out.println("ns=" + ns);
          int len = ns.length();
          HashSet<Integer> sss = new HashSet<Integer>();
          for (int i = 1; i < len; i++) {
            String ns1 = ns.substring(0, i);
            String ns2 = ns.substring(i, len);
            // System.out.printf("ns1=%s ns2=%s\n",ns1,ns2);
            if (ns2.charAt(0) == '0')
              continue;
            String ms = ns2 + ns1;
            // System.out.println("ms="+ms);
            int m = Integer.parseInt(ms);
            if (sss.contains(m))
              continue;
            if (n < m && m <= b) {
              y++;
              sss.add(m);
//              System.out.printf("%d <= %d < %d <= %d\n", a, n, m, b);
            }
          }
        }
      }
      System.out.printf("Case #%d: %d\n", tc, y);

      tc++;
    }
  }
}
