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

import org.jfree.data.function.PowerFunction2D;

public class r2a
{

	Map numMap = new HashMap();
    int output = 0;

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        r2a mk = new r2a();
        try {
            FileInputStream fstream = new FileInputStream("d:/cjinput.txt");
            DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            String str;
            int i = 0;
            while ((str = br.readLine()) != null) {
            	int begin=0,end = 0;
                i++;
                if (i == 1)
                    continue;
                mk.numMap = new HashMap();
                StringTokenizer strTok = new StringTokenizer(str, " ");
                while (strTok.hasMoreTokens()) {
                	begin =  Integer.parseInt(((String) strTok.nextToken()));
                    end = Integer.parseInt(((String) strTok.nextToken()));
                }

                mk.evaluate(i, begin, end);

            }
            in.close();
        }
        catch (Exception e) {
            System.err.println(e);
        }

    }

    private void evaluate(int rowNum, int begin, int end)
    {
    	output=0;
    	for (int i = begin; i<= end; i++) {
    		if(numMap.containsKey(Integer.valueOf(i)))
    			continue;
    		List l = getPairElems(i);
    		if (l.size() > 0) {
    			Iterator itr = l.iterator();
    			int ctr = 0;
    			ArrayList tempList = new ArrayList();
    			while (itr.hasNext()) {
    				int next = ((Integer)itr.next()).intValue();
    				if (next <= end && next > i) {
    					numMap.put(Integer.valueOf(next), i);
    					tempList.add(next);
    					ctr++;
    				}
    			}
    			ctr = getCounter(ctr+1,2);
/*    			if (tempList.size() > 0 || ctr > 0)
    				System.out.println("DD: " + i + ": " + tempList +" ; ctr = " + ctr);*/
    			output = output + ctr;
    		}
    		
    	}

        String outputStr = "Case #" + (rowNum -1) + ": " + output;
        
        System.out.println(outputStr);
    }

	private int getCounter(int n, int r) {
		int ret = 1;
		int nfactorial =1;
		for (int i = 2; i<=n; i++) {
			nfactorial = i*nfactorial;
		}
		int nrfact =1;
		for (int i = 2; i<=n-r; i++) {
			nrfact = i*nrfact;
		}
		
		return nfactorial/(2*nrfact);
	}

	private ArrayList getPairElems(int num) {
		ArrayList retList = new ArrayList();
		int temp = num;
		if (num/10 == 0)
			return retList;
		
		String str = String.valueOf(num);
		
		int arr[] = new int[str.length()];
		int x = str.length();
		while (temp/10 > 0) {
			arr[x-1] = temp%10;
			temp=temp/10;
			x--;
		}
		arr[0]=temp;
		
		int size = arr.length;
		for (int pos = size -1; pos >0; pos--) {
			if(arr[pos] == 0)
				continue;
			int pairNum = 0;
			int multiplier =1;
			for (int c=0; c < size-1; c++) {
				multiplier = multiplier*10;
			}
			pairNum = pairNum + (arr[pos]*multiplier);
			for(int ctr = pos+1, i=1; i < size; i++,ctr++) {
				if (ctr == size)
					ctr=0;
				if (multiplier!=1)
					multiplier=multiplier/10;
				pairNum = pairNum + (arr[ctr]*multiplier);
			}
			if (pairNum != num)
				retList.add(Integer.valueOf(pairNum));			
		}
		
		return retList;
	}
}

import java.io.File;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Solver {
    
    private final static String DIR_PATH = "e:\\jam\\"; 
    private final static String IN_FILE_NAME = "C-large.in";
    private final static String OUT_FILE_NAME = IN_FILE_NAME.replaceAll("\\..*$", ".out");
    
    private final static File sInFile = new File(DIR_PATH, IN_FILE_NAME);
    private final static File sOutFile = new File(DIR_PATH, OUT_FILE_NAME);
        
    private final PrintStream mOut;
    private final Scanner mScanner;
    
    private static class ProxyOutputStream extends FilterOutputStream {
        public ProxyOutputStream(OutputStream out) {
            super(out);
        }
        
        @Override
        public void write(byte[] b, int off, int len) throws IOException {
            System.out.write(b, off, len);
            super.write(b, off, len);
        }        
    }
    
    public static void main(String[] args) {        
        try {
            Solver solver = new Solver(sInFile, sOutFile);
            solver.solve();
        } catch(IOException ex) {
            ex.printStackTrace();
        }
    }    
    
    public Solver(File inFile, File outFile) throws IOException {
        mScanner = new Scanner(inFile);
        mOut = new PrintStream(new ProxyOutputStream(new FileOutputStream(outFile)));
    }
    
    private void printSolution(int no, String solution) {
        if(no == 0) {
            throw new IllegalArgumentException("Solution number is 0! Should start with 1!");
        }
        mOut.println(String.format("Case #%d: %s", no, solution));
    }
    
    private void solve() throws IOException {
        int problemsCount = mScanner.nextInt();
        mScanner.nextLine();
        for(int i = 0; i < problemsCount; i++) {
            long min = mScanner.nextLong();
            long max = mScanner.nextLong();
            String solution = Long.toString(solve(min, max));
            printSolution(i + 1, solution);
        }
    }
    
    int convert(int [] digits, int d0, long number) {
        while(number > 0) {
            digits[d0] = (int)(number % 10);
            d0--;
            number /= 10;
        }
        return d0 + 1;
    }
    
    long convertToInt(int [] digits, int d0, int dlen) {
        long number = 0;
        for(int i = 0; i < dlen; i++) {
            number = number * 10 + digits[d0 + i]; 
        }
        return number;
    }
    
    //true if r > d
    boolean isGreater(int [] r, int r0, int [] d, int d0, int len) {
        for(int i = 0; i < len; i++) {
            int delta = r[r0 + i] - d[d0 + i];
            if(delta > 0) {
                return true;
            } else if(delta < 0) {
                return false;
            }
        }
        return false;
    }
    
    private long solve(long min, long max) {
        if(max < 10) {
            return 0;
        }
        
        long counter = 0;
        
        int [] max_digits = new int[8];
        int max_d0 = convert(max_digits, max_digits.length - 1, max);
        
        int [] digits = new int [7 + 1 + 7];
        int d0 = 7;//points to least significant digit in array
                
        Set<Long> unique = new HashSet<Long>();
        for(long number = min; number <= max; number++) {
            unique.clear();
            
            /* convert number to array */
            int n0 = convert(digits, d0, number);
            int dlen = d0 - n0 + 1; 
            
            /* duplicate digits */
            for(int i = 0; i < dlen - 1; i++) {
                digits[d0 + i + 1] = digits[n0 + i];
            }
                        
            /* count recycled numbers */
            boolean printed = false;
            for(int i = 0; i < dlen - 1; i++) {
                
                int r0 = n0 + i + 1;//r0 for current recycled number
                //print(digits, r0, dlen);
                if(digits[r0] == 0) {
                    //System.out.println(" - nope, leading zero.");
                    continue;//invalid case 
                }
                
                /* is recycled number greater than original one? */
                boolean greater = isGreater(digits, r0, digits, n0, dlen);
                /* is recycled number grater than max? */
                boolean valid = !isGreater(digits, r0, max_digits, max_d0, dlen);
                
                if(greater && valid) {
                    //System.out.println(" - yes.");
                    if(!printed) {
                        //print(digits, n0, dlen);
                        //System.out.println(" => ");
                        printed = true;
                    }
                    //System.out.print("  ");
                    //print(digits, r0, dlen);
                    
                    unique.add(convertToInt(digits, r0, dlen));
                } else {
                    if(!greater) {
                        //System.out.println(" - nope, not greater than original.");
                    } else {
                        //System.out.println(" - nope, greater than max.");
                    }
                }
            }
            if(printed) {
                //System.out.println();
            }
            counter+=unique.size();
            //System.out.println("----");
        }        
        return counter;
    }
    
    void print(int [] digits, int d0, int dlen) {
        for(int i = d0; i < d0 + dlen; i++) {
            System.out.print(digits[i]);
        }
    }
    
    void println(int [] digits, int d0, int dlen) {
        print(digits, d0, dlen);
        System.out.println();
    }
}
