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();
    }
}

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

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

/**
 *
 * @author karthik
 */
public class JavaApplication11 {

    /**
     * @param args the command line arguments
     */
    public static int isrotate(String c,int n)
    {
        String c1=new String();
        for(int i=c.length()-n;i<c.length();i++)
        c1+=c.charAt(i);
        c1+=c.substring(0,c.length()-n);
        int a1=Integer.parseInt(c1);
        return a1;
    }
    public static void main(String[] args) throws FileNotFoundException, IOException 
    {
        // TODO code application logic here
        //HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
        FileInputStream f=new FileInputStream("large");
        DataInputStream dis=new DataInputStream(f);
        BufferedReader br=new BufferedReader(new InputStreamReader(dis));
        ArrayList<Integer> al=new ArrayList<Integer>();
        int n=Integer.parseInt(br.readLine());
        int a,b,count=0;
        String s[];
        int temp,temp1;
        for(int i=0;i<n;i++)
        {
            s=br.readLine().split(" ");
            a=Integer.parseInt(s[0]);
            b=Integer.parseInt(s[1]);
            for(int j=a;j<b;j++)
            {
                String str=String.valueOf(j);
                int m=str.length();
                int x=0;
                
                HashMap<Integer,Integer> h=new HashMap<Integer,Integer>();
                for(int k=1;k<m;k++)
                {
                    x=isrotate(String.valueOf(j),k);
                    if(a<=j && j<x && x<=b)
                    {
                        if(h.containsKey(j) && h.get(j)==x)
                        {
                            ;
                        }
                        else
                        {
                        //System.out.println(j+","+x);
                        h.put(j,x);
                        count++;
                        }
                    }
                }
                h=null;
            }
            
            System.out.println("Case #"+(i+1)+": "+count);
            count=0;
        }   
    }
}
