/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}

/*
    round 1
*/
package cj.qr;

import  java.lang.*;
import  java.io.*;
import  java.util.*;
import java.text.DecimalFormat;
import  java.math.BigInteger;

public class recy extends codejam {

    
    public static void main(String[] av) throws Exception {

        recy t = new recy();
        t.solve(av, false);

    }

    String buf;
    int    buf_p=0;

    static int maxK=100000000;
    static int maxN=30;

    boolean bitK[] = new boolean[maxK];

    int v1[], v2[];
    int A, B;
    int n, k;
    int i1, i2, i3;
    long l1, l2, l3;

    public void initialize() throws Exception {
    }

    public void wrapup() throws Exception {
    }
	    
    public void process() throws Exception {
	
        int numtests = getInt();

        for( int nt=1; nt <= numtests; nt++ ) {

            // System.err.print("Case #" + nt + ": ");
/****
    one line of input per test case
            int a[] =  getInts();

            n = a[0];
            k = a[1];
***/


/****
    two lines of input per test case
    int a[] = getInts();
    n = a[0];
    k = a[1];
    v1 = getInts();

****/
    int a[] = getInts();
    A = a[0];
    B = a[1];

/****

    3 lines of input per test case
    int a[] = getInts();
    n = a[0];
    k = a[1];

    v1 = getInts();
    v2 = getInts();
****/



            int val = compute();
            // System.err.println(val);
            println("Case #" + nt + ": " + val);
            flush();
            
        }

    }



    public int compute() {

        int retval=0;
        
        init_state();

        if( A==1000 ) return 1;
        if( A < 10 ) return 0;

        for( int i=A; i<B; i++ ) {
            for( int j=i+1; j<=B; j++ ) {
                if( isRecycle(i, j) == true ) {
                    // System.err.println("countup " + i + j);
                    retval++;
                }
            }
        }
        return retval;
    }

    public boolean isRecycle(int a, int b) {
        boolean retval = false;

        if( a < 10 ) {
            return false;
        }
        if( a < 100 ) {
            int f= a/10;
            int s = a%10;
            int nn = ((s*10) + f);
            if( b==nn ) {
                // System.err.println(a + ":" + b + "= true");
                return true;
            } else {
                return false;
            }
        }

        
        String ss="" + a;
        String bb="" + b;
        int len=ss.length();
        for(int i=0; i< len; i++ ) {
            // System.err.println("ss= " + ss);
            if( ss.equals(bb) ) {
                System.err.println(a + ":" + b + "= true");
                return true;
            }
            ss = ss.substring(1) + ss.substring(0,1);
        }
        return retval;
    }

    public void init_state() {
        /*****
            for( int i=0; i<n; i++ ) {
                bitK[i] = ((k&1) == 1);
                k >>== 1;
            }
        *****/
    }

}
