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.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * Google Code Jam 2012
 * 	Qualifier Round
 * 	Problem C
 * 
 * @author Brian Crockford
 */
public class GCJ20120C {
	public static final String inputFilename = "C-large.in";	

	
	
	static class LongPair {		
		final long[] data = new long[2];
		
		public LongPair(long x, long y) {
			set(x, y);
		}
		
		public long getX() { return data[0]; }
		public long getY() { return data[1]; }
		public void set(long x, long y) {
			data[0] = Math.min(x,y); data[1] = Math.max(x,y);
		}
		
		@Override public boolean equals(Object o) {
			LongPair p = (LongPair) o;
			if (null != p) {
				return (data[0] == p.getX() && data[1] == p.getY())
						|| (data[1] == p.getY() && data[0] == p.getX());
			}
			return false;
		}
		
		@Override public int hashCode() {
	        long hash = 1;
	        hash = hash * 31 + data[0];
	        hash = hash * 31 + data[1];
	        return (int) hash;
		}
	}
	
	static class DataSet {
		private static HashSet<LongPair> pairs;
		static {
			pairs = new HashSet<LongPair>(500000);
		}
		
		public long begin,
					end;
		
		@Override
		public String toString() {
			return new StringBuilder("<$DataSet: ").append(begin).append(", ").append(end).append(">").toString();
		}
		
		public long countRecycles() {
			int digits = countDigits(begin);
			for (long i=begin; i<=end; ++i) {
				for (int j=1; j<digits; ++j) {
					long result = shiftLong(i, j);
					if (i != result && result >= begin && result <= end)
						pairs.add(new LongPair(i, result));
				}
			}
			long result = pairs.size();
			pairs.clear();
			return result;
		}
		
		public static DataSet parse(String s) {
			DataSet result = new DataSet();
				result.begin = Long.parseLong(s.substring(0, s.indexOf(' ')));
				result.end = Long.parseLong(s.substring(1+s.indexOf(' ')));
			return result;
		}
	}
	
	
	
	public static Reader getFileReader(String filename) {
		BufferedReader result = null;
		try {
			result = new BufferedReader(new FileReader(filename));
		}
		catch (FileNotFoundException e) {
			System.err.println("Couldn't find the file \""+filename+"\"");
			e.printStackTrace();
		}
		return result;
	}
	
	
	
	public static String readLine(BufferedReader reader) {
		try {
			return reader.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	
	
	public static void closeReader(Reader r) {
		try { 
			r.close(); 
		} catch (IOException e) { e.printStackTrace(); }
	}
	
	
	
	public static Writer getFileWriter(String filename) {
		BufferedWriter result = null;
		try {
			result = new BufferedWriter(new FileWriter(filename));
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	
	
	public static void writeLine(BufferedWriter writer, String line) {
		try {
			writer.write(line);
			writer.newLine();
		} catch (IOException e) { e.printStackTrace(); }
	}
	
	
	
	public static void closeWriter(Writer w) {
		try { 
			w.close(); 
		} catch (IOException e) { e.printStackTrace(); }
	}
	
	
	
	public static String formatCase(int caseNumber, long result) {
		return new StringBuilder("Case #").append(caseNumber).append(": ").append(result).toString();
	}
	
	
	
	public static int countDigits(long n) {
		return (int) 1 + (int)Math.floor(Math.log10(n));
	}
	
	
	public static int getDigit(long n, int digit) {
		return(int)(n/(long)Math.pow(10, digit-1)) % 10;
	}
	
	
	public static long shiftLong(long n, int digits) {
		long mask = (long) Math.pow(10, digits);
		long upshift = (long) Math.pow(10, (countDigits(n)-digits));
		return (upshift*(n%mask)) + (n/mask);		
	}
	
	
	
	public static void main(String[] args) {		
		BufferedReader in = (BufferedReader) getFileReader(inputFilename);
		int lineCount = Integer.parseInt(readLine(in));
		List<DataSet> dataSets = new ArrayList<DataSet>();
		for (int i=0; i<lineCount; ++i) {
			dataSets.add(DataSet.parse(readLine(in)));
		}
		closeReader(in);
		
		BufferedWriter out = (BufferedWriter) getFileWriter(inputFilename.replace(".in", ".out"));
		for (int i=0; i<lineCount; ++i) {
			long result = dataSets.get(i).countRecycles();
			System.out.println(formatCase(i+1, result));
			writeLine(out, formatCase(i+1, result));
		}
		closeWriter(out);
	}

}