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

public class recycled_numbers {
	public static void main(String[]a) throws Exception{
		
		Scanner f = new Scanner(new File(a[0]));
		int result=0;
		int A,B;
		String n,m;
		HashSet<String> s=new HashSet<String>();
		
		int T=f.nextInt();	//T total case count
		for (int t=1; t<=T;t++){//for each case t
			
			s.clear();
			result=0;				//reset
			A=f.nextInt();B=f.nextInt();	//get values for next case
			
			if (A==B)result=0;//remove case not meeting problem limits 
			else{
				for(int i=A;i<=B;i++){//for each int in range
					n=Integer.toString(i);
					m=new String(n);
					//System.out.println(n);
					for (int j=1;j<n.length();j++){//move each digit to the front & test
						m = m.substring(m.length()-1)+m.substring(0,m.length()-1);
						if(m.matches("^0+[\\d]+")!=true &&
								Integer.parseInt(m)<=B &&
								Integer.parseInt(n)<Integer.parseInt(m)){
							s.add(new String(n+","+m));
							//result++;
							//System.out.println(" matched: "+m);
						}
						
					}
				}
				result = s.size();
			}

			//display output
			System.out.println("Case #" + t + ": " + result);
		}
	}
}
import java.io.*;
import java.util.*;
import java.math.*;

import static java.lang.System.out;
// import static java.lang.Math.*;

public class BaiC implements Runnable {

  public void run() {
    int ntest = nextInt();
    int[] ndigits = new int[2000001];
    for (int i = 0; i < 10; ++i) {
      ndigits[i] = 1;
    }
    for (int i = 10; i < ndigits.length; ++i) {
      ndigits[i] = ndigits[i / 10] + 1;
    }
    int[] p10 = new int[9];
    p10[0] = 1;
    for (int i = 1; i < p10.length; ++i)
      p10[i] = p10[i - 1] * 10;
    int[] s = new int[111];
    for (int test = 1; test <= ntest; ++test) {
      out.print("Case #" + test + ": ");

      int A = nextInt();
      int B = nextInt();

      int res = 0;
      for (int i = A; i < B; ++i) {
        int x = i;
        int nd = ndigits[x];
        int ns = 0;
        for (int k = 1; k < nd; ++k) {
          x = x / 10 + x % 10 * p10[nd - 1];
          if (i < x && x <= B) {
            boolean ok = true;
            for (int j = 0; j < ns; ++j) if (x == s[j]) ok = false;
            if (ok) {
              s[ns++] = x;
              ++res;
            }
          }
        }
      }

      out.println(res);
    }
  }

    int[] ar(int st, int en) { int[] res = new int[Math.max(en - st, 0)]; for (int i = st; i < en; ++i) res[i - st] = i; return res; }
    int[] ar(int n) { return ar(0, n); }
    void viet(Object...os) { System.err.println(Arrays.deepToString(os)); }
    BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer strtok = null;

    String nextStr() {
        try {
            while(strtok == null || !strtok.hasMoreTokens())
                strtok = new StringTokenizer(keyboard.readLine());
            return strtok.nextToken();
        }
        catch(Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
            return null;
        }
    }

    int nextInt() {
        return Integer.parseInt(nextStr());
    }

    long nextLong() {
        return Long.parseLong(nextStr());
    }

    double nextDouble() {
        return Double.parseDouble(nextStr());
    }

    public static void main(String[] args) {
        new BaiC().run();
    }
}