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

/**
 *
 * @author eblanco
 */
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import javax.swing.JFileChooser;

public class RecycledNumbers {

    public static String DatosArchivo[] = new String[10000];

    public static int[] convertStringArraytoIntArray(String[] sarray) throws Exception {
        if (sarray != null) {
            int intarray[] = new int[sarray.length];
            for (int i = 0; i < sarray.length; i++) {
                intarray[i] = Integer.parseInt(sarray[i]);
            }
            return intarray;
        }
        return null;
    }

    public static boolean CargarArchivo(String arch) throws FileNotFoundException, IOException {
        FileInputStream arch1;
        DataInputStream arch2;
        String linea;
        int i = 0;

        if (arch == null) {
            //frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
            int rc = fc.showDialog(null, "Select a File");
            if (rc == JFileChooser.APPROVE_OPTION) {
                arch = fc.getSelectedFile().getAbsolutePath();
            } else {
                System.out.println("No hay nombre de archivo..Yo!");
                return false;
            }
        }
        arch1 = new FileInputStream(arch);
        arch2 = new DataInputStream(arch1);
        do {
            linea = arch2.readLine();
            DatosArchivo[i++] = linea;
            /* if (linea != null) {
            System.out.println(linea);
            }*/
        } while (linea != null);
        arch1.close();
        return true;
    }

    public static boolean GuardaArchivo(String arch, String[] Datos) throws FileNotFoundException, IOException {
        FileOutputStream out1;
        DataOutputStream out2;
        int i;
        out1 = new FileOutputStream(arch);
        out2 = new DataOutputStream(out1);

        for (i = 0; i < Datos.length; i++) {
            if (Datos[i] != null) {
                out2.writeBytes(Datos[i] + "\n");
            }
        }
        out2.close();
        return true;
    }

    public static void echo(Object msg) {
        System.out.println(msg);
    }

    public static void main(String[] args) throws IOException, Exception {
        String[] res = new String[10000], num = new String[2];
        int i, j, k, ilong;
        int ele = 1;
       ArrayList al = new ArrayList();
        String FName = "C-small-attempt0",  istr, irev, linea;
        if (CargarArchivo("C:\\eblanco\\Desa\\CodeJam\\Code Jam\\test\\" + FName + ".in")) {
            for (j = 1; j <= Integer.parseInt(DatosArchivo[0]); j++) {
                linea = DatosArchivo[ele++];
                num = linea.split(" ");
                   al.clear();
                // echo("A: "+num[0]+" B: "+num[1]);
                for (i = Integer.parseInt(num[0]); i <= Integer.parseInt(num[1]); i++) {
                    istr = Integer.toString(i);
                    ilong = istr.length();
                 
                    for (k = 1; k < ilong; k++) {
                        if (ilong > k) {
                            irev = istr.substring(istr.length() - k, istr.length()) + istr.substring(0, istr.length() - k);
                            //echo("caso: " + j + ": isrt: " + istr + " irev: " + irev);
                            if ((Integer.parseInt(irev) > Integer.parseInt(num[0])) && (Integer.parseInt(irev) > Integer.parseInt(istr)) && (Integer.parseInt(irev) <= Integer.parseInt(num[1]))) {
                                al.add("(" + istr + "," + irev + ")");
                            }
                        }
                    }
                }
                HashSet hs = new HashSet();
                hs.addAll(al);
                al.clear();
                al.addAll(hs);
                res[j] = "Case #" + j + ": " + al.size();
                echo(res[j]);
                LeerArchivo.GuardaArchivo("C:\\eblanco\\Desa\\CodeJam\\Code Jam\\test\\" + FName + ".out", res);
            }
        }
    }
}

import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;


public class Test{
   public static void main(String[] args)
        throws IOException {

        BufferedReader inputStream = null;
        PrintWriter outputStream   = null;
        //test();
        
        try {
            inputStream = 
                new BufferedReader(new FileReader("test.in"));
            outputStream = 
                new PrintWriter(new FileWriter("test.out"));

            String l;
            l = inputStream.readLine();
            int t = Integer.parseInt(l);
            int i = 1;
            while ((l = inputStream.readLine()) != null) {
                String result = "Case #"+(i++)+": "+getNum(l);
                outputStream.println(result);
                System.out.println(result);
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
            if (outputStream != null) {
                outputStream.close();
            }
        }
    }
    
    /*public static void test(){
        int begin = 1111;
        int end   = 2222;
        int valueSize = 4;
        int testValue = begin;
        
        int a = 0;
        for(testValue = begin;testValue<=end;testValue++){
            
            for(int i=1;i<valueSize;i++){
                int tmp = getLeftValue(testValue,valueSize,i);
                if(tmp>testValue&&tmp<end){
                    a++;
                }
            }
        }
        
        System.out.println(a);
    }
    public static int getLeftValue(int testValue,int valueSize,int leftSize){
        
        
        
        if(valueSize==2){
            int a0 = testValue%10;
            int a1 = testValue/10;
            if(a0==0){
                return -1;
            }
            return a0*10+a1;
        }
        else if(valueSize==3){
            if(leftSize==1){
                int a0 = testValue%10;
                int a1 = testValue/10;
                if(a0==0){
                    return -1;
                }
                return a0*100+a1;
            }
            else if(leftSize==2){
                int a0 = testValue%100;
                int a1 = testValue/100;
                if(a0<10){
                    return -1;
                }
                return a0*10+a1;
            }
        }
        else if(valueSize==4){
            if(leftSize==1){
                int a0 = testValue%10;
                int a1 = testValue/10;
                if(a0==0){
                    return -1;
                }
                return a0*1000+a1;
            }
            else if(leftSize==2){
                int a0 = testValue%100;
                int a1 = testValue/100;
                if(a0<10){
                    return -1;
                }
                return a0*100+a1;
            }
            else if(leftSize==3){
                int a0 = testValue%1000;
                int a1 = testValue/1000;
                if(a0<100){
                    return -1;
                }
                return a0*10+a1;
            }
        }
        return 0;
    }*/
    
    public static int getNum(String l){
        
        int valueSize = l.length()/2;
        
        if(valueSize==1){return 0;}
        
        String[] strArray = l.split(" ");
        int begin = Integer.parseInt(strArray[0]);
        int end   = Integer.parseInt(strArray[1]);
        
        end++;
        int testValue = begin;
        int returnValue = 0;
        int i,tmp;
        
        
        while(testValue<end){
            
            for(i=1;i<valueSize;i++){
                tmp = getLeftValue(testValue,valueSize,i);
                if(tmp>testValue&&tmp<end){
                    
                    returnValue++;
                }
           
            }
            
            testValue++;
        }
        
        //for(i=0;i<288;i++){
            //    if(returnValueArray[i]==testValueArray[j]){
            //        if(returnValueArray[j]==testValueArray[i])
            //        System.out.println(testValueArray[i]+" -> "+returnValueArray[i]+"    ("+step[i]+")");
            //          +"       "+testValueArray[i]+" -> "+returnValueArray[i]);
            //    }
            //}
        //}
        
        return returnValue;
    }
    
    public static int getLeftValue(int testValue,int valueSize,int leftSize){
        
        int a0 = testValue%10;
        int a1 = (testValue%100)/10;
        int a2 = (testValue%1000)/100;
        int a3 = (testValue)/1000;
        
        if(valueSize==2){
            if(a0==0){
                return -1;
            }
            return a0*10+a1;
        }
        else if(valueSize==3){
            if(leftSize==1){
                if(a1==0){
                    return -1;
                }
                return a1*100+a0*10+a2;
            }
            else if(leftSize==2){
                if(a0==0){
                    return -1;
                }
                return a0*100+a2*10+a1;
            }
        }
        else if(valueSize==4){
            if(leftSize==1){
                if(a2==0){
                    return -1;
                }
                return a2*1000+a1*100+a0*10+a3;
            }
            else if(leftSize==2){
                if(a1==0){
                    return -1;
                }
                return a1*1000+a0*100+a3*10+a2;
            }
            else if(leftSize==3){
                if(a0==0){
                    return -1;
                }
                return a0*1000+a3*100+a2*10+a1;
            }
        }
        return 0;
    }
}