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

package Jam;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

public class ProblemC {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ProblemC p = new ProblemC();
		p.readAndOutput();
	}
	
	public int cmp(byte[] s1,int start,byte[]s2)
	{
		int tmp = 0;
		for( int i = 0;i<s2.length;i++ )
		{
			tmp = (i + start )%s1.length;
			if( s1[tmp] == s2[i] )
				continue;
			return s1[tmp] - s2[i];
		}
		return 0;
	}
	byte min[];
	byte max[];
	HashMap<String,Integer> hm;
	
	
	public void print(byte[] tmp,int st)
	{
		StringBuffer sb = new StringBuffer();
		for( int i = 0;i<tmp.length;i++ )
		{
			sb.append((char)tmp[i]);
		}
		for( int i = 0;i<tmp.length;i++ )
		{
			sb.append((char)tmp[(i + st )%tmp.length]);
		}
		String x = sb.toString();
		hm.put(x, 1);
	}
	
	public int l_cal(byte[] tmp,int pos,int st)
	{
		
		if( pos >= tmp.length )
		{
			if( st == -1 )
				return 0;
			if( cmp(tmp,0,min) >=0 && cmp(tmp,0,max) <=0 && cmp(tmp,st,min) >=0 && cmp(tmp,st,max) <=0 )
			{
				print(tmp,st);
				return 1;
			}else
			{
				return 0;
			}
		}
		int sum = 0;
		byte k;
		if( st == -1 )
		{
			k = (byte) (tmp[0] + 1);
			for(;k<=max[0];k++)
			{
				tmp[pos] = k;
				sum += l_cal(tmp,pos+1,pos);
			}
		}
		for( k = '0'; k <= '9'; k++ )
		{
			tmp[pos] = k;
			sum += l_cal(tmp,pos+1,st);
		}
		return sum;
	}
	
	public int m_cal(byte[] tmp,int pos,int st)
	{
		
		if( pos >= tmp.length )
		{
			if( st == -1 )
				return 0;
			if( cmp(tmp,st,tmp) > 0 && cmp(tmp,0,min) >=0 && cmp(tmp,0,max) <=0 && cmp(tmp,st,min) >=0 && cmp(tmp,st,max) <=0 )
			{
				print(tmp,st);
				return 1;
			}else
			{
				return 0;
			}
		}
		int sum = 0;
		byte k;
		if( st == -1 )
		{
			tmp[pos] = tmp[0];
			sum += m_cal(tmp,pos+1,pos);
		}
		for( k = '0'; k <= '9'; k++ )
		{
			tmp[pos] = k;
			sum += m_cal(tmp,pos+1,st);
		}
		return sum;
	}
	public int cal()
	{
		int sum = 0;
		byte tmp[] = new byte[min.length];
		
		int range = max[0] - min[0] + 1;
		int len = min.length;
		
		hm = new HashMap<String,Integer>();
		
		for( int i = 0; i<range;i++ )
		{
			tmp[0] = (byte) (min[0] + i);
			sum += l_cal(tmp,1,-1);
			sum += m_cal(tmp,1,-1);
		}
		
		
		return hm.size();
	}
	
	public String doChange(String in)
	{
		String[] test = in.split(" ");
		min = test[0].getBytes();
		max = test[1].getBytes();
		
		System.out.println(in);
		return Integer.toString(cal());
	}
	
	public void readAndOutput()
	{
		File file = new File("C-large.in");
		File out = new File("out.txt");
		BufferedReader reader = null;
		BufferedWriter writer = null;
		int i = 0;
        try {
        	reader = new BufferedReader(new FileReader(file));
        	writer = new BufferedWriter(new FileWriter(out));
            String temp;
            while ((temp = reader.readLine()) != null) {
            	
            	if( i == 0 )
            	{
            		i = 1;
            		continue;
            	}
        		writer.write("Case #" + i +": " + doChange(temp)+"\n");
        		i++;
            }
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
	}

}
