import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class C{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	int caze, T;
	int A, B;

	void run(){
		T=sc.nextInt();
		for(caze=1; caze<=T; caze++){
			A=sc.nextInt();
			B=sc.nextInt();
			solve();
		}
	}

	void solve(){
		int ans=0;
		for(int n=A; n<=B; n++){
			int digit=(int)(log10(n)+EPS);
			int d=(int)pow(10, digit);
			// debug("n", n);
			for(int m=rot(n, d); m!=n; m=rot(m, d)){
				// debug("m", m);
				if(n<m&&m<=B){
					ans++;
				}
			}
		}
		answer(ans+"");
	}

	int rot(int n, int d){
		return n/10+n%10*d;
	}

	void answer(String s){
		println("Case #"+caze+": "+s);
	}

	void println(String s){
		System.out.println(s);
	}

	void print(String s){
		System.out.print(s);
	}

	void debug(Object... os){
		System.err.println(deepToString(os));
	}

	public static void main(String[] args){
		try{
			System.setIn(new FileInputStream("dat/C-small.in"));
			System.setOut(new PrintStream(new FileOutputStream("dat/C-small.out")));
		}catch(Exception e){}
		new C().run();
		System.out.flush();
		System.out.close();
	}
}

import java.io.BufferedReader;
import java.io.FileReader;


public class C {

  private boolean isR(int a, int b) {

    char[] sa = String.valueOf(a).toCharArray();
    char[] sb = String.valueOf(b).toCharArray();

    if (sa.length != sb.length) return false;
    int n = sa.length;

    for (int i = 1; i < n; i++) {
      boolean ok = true;
      for (int k = 0; k < n; k++) {
        char c = sb[(k + i) % n];
        if (c != sa[k]) {
          ok = false;
          break;
        }
      }
      if (ok) return true;
    }

    return false;
  }

  int count(int a, int b) {
    int c = 0;
    for (int i = a; i < b; i++) {
      for (int j = i + 1; j <= b; j++) {
        if (isR(i, j)) {
          c++;
        }
      }
    }
    return c;
  }

  private void main2(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new FileReader(args[0]));
    String line = br.readLine();
    int count = Integer.parseInt(line);
    for (int i = 0; i < count; i++) {
      line = br.readLine();
      int s = line.indexOf(' ');
      int a = Integer.parseInt(line.substring(0, s));
      int b = Integer.parseInt(line.substring(s + 1));
      System.out.println("Case #" + (i + 1) + ": " + count(a, b));
    }
    br.close();
  }

  public static void main(String[] args) throws Exception {
    new C().main2(args);
  }


}
