import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Recycled {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            int t = Integer.parseInt(br.readLine());
            for (int i = 0; i < t; i++) {
                String[] str = br.readLine().split(" ");
                int a = Integer.parseInt(str[0]);
                int b = Integer.parseInt(str[1]);
                System.out.println("Case #" + (i + 1) + ": " + find(a, b));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int find(int a, int b) {
        HashSet<Long> used = new HashSet<Long>();
        int digits = String.valueOf(a).length();
        if (digits == 1) return 0;
        for (int i = a; i <= b; i++) {
            int s = 10;
            int m = (int) Math.pow(10, digits-1);
            for (int j = 0; j < digits-1; j++) {
                int r = i % s;
                if (r < s/10) continue;
                int q = i / s;
                int rn = r * m + q;
                s *= 10; m /= 10;
                if (i != rn && rn >= a && rn <= b) {
                    long pp;
                    if (rn < i) pp = (long)rn << 30 | i;
                    else pp = (long)i << 30 | rn;
                    if (!used.contains(pp)) {
                        used.add(pp);
                    }
                }
            }
        }
        return used.size();
    }
}


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

/**
 * @author Addy
 */
public final class CodeJamIO
{

    private static final String input = ".in";
    private static final String output = ".out";
    //input
    private final Scanner sc;
    private final PrintStream ps;
    private int index;
    private final int size;
    //data
    private int min;
    private int max;

    public CodeJamIO(String file)
    {
        Scanner tussensc = null;
        PrintStream tussenps = null;
        try
        {
            tussensc = new Scanner(new File(file + input));
            tussenps = new PrintStream(new File(file + output));
        }
        catch(FileNotFoundException ex)
        {
            ex.printStackTrace(System.err);
            System.exit(1);
        }
        sc = tussensc;
        ps = tussenps;
        index = 0;
        size = sc.nextInt();
        //init
        init();
        next();
    }

    public void print(String solution)
    {
        ps.println("Case #" + index + ": " + solution);
    }

    public boolean hasMore()
    {
        return index < size;
    }

    public void close()
    {
        sc.close();
        ps.close();
    }

    public void init()
    {
    }

    public void next()
    {
        min = sc.nextInt();
        max = sc.nextInt();
        index++;
    }

    public void solve()
    {
        //calc
        int opl = 0;

        int tien2 = 10;
        while(tien2 <= min)
            tien2 *= 10;
                    HashSet<Integer> set = new HashSet<>();
        for(int n = min; n < max; n++)
        {
            set.clear();
            int tien = 10;
            while(tien < n)
            {
                final int deel = n / tien;
                final int rest = n % tien;
                int m = (rest * tien2 / tien) + deel;
                if(n < m && m <= max)
                {
                    if(!set.contains(m))
                    {
                        set.add(m);
                        opl++;
                    }
                }
                tien *= 10;
            }
        }
        //print
        print(Integer.toString(opl));
    }

    public static void main(String[] args)
    {
        CodeJamIO cd = new CodeJamIO("C-large");
        cd.solve();
        while(cd.hasMore())
        {
            cd.next();
            cd.solve();
        }
        cd.close();
    }

}
