import java.io.*;

class code1
{
	public static void main(String args[]) throws Exception 
	{
		File ii = new File ("C-small-attempt1.in");
		FileInputStream fis = new FileInputStream(ii);
		BufferedReader  br = new BufferedReader(new InputStreamReader (fis));
		int cases = Integer.parseInt(br.readLine());
		FileOutputStream fout = new FileOutputStream ("output.txt");
		DataOutputStream dout = new DataOutputStream (fout);
		int total=0;
		for(int i=0;i<cases;i++){
		String temp = br.readLine();
		String parts [] = temp.split(" ");
		int lower = Integer.parseInt(parts[0]);
		int upper = Integer.parseInt(parts[1]);
		System.out.println(lower+" "+upper);
		
		for(int j=lower;j<=upper;j++)
		{
			int abc = j;int length=0;
			if(j<10)continue;
			while (abc!=0){abc/=10;length++;}
			abc=j;
			for(int m=0;m<length-1;m++){
				int shift = abc%10;
				abc=abc/10;
				System.out.println("hi "+j);
				abc=abc+shift*power(10,length-1);
				if(abc<=upper&&shift!=0&&abc>j)total++;
				System.out.println(total);
			}
		}
 		dout.writeBytes("Case #"+(i+1)+ ": "+total+"\n");
 		total=0;
		}//for close
		
	}

	private static int power(int i, int j) {
		int no=1;
		for(int a=0;a<j;a++){no=10*no;}
		return no;
	}
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package solution;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

/**
 *
 * @author 144key (tux_daemon)
 */
public class Main {
    // Problem 3 : Problem C. Recycled Numbers
    public static void recycledNumbers(String fileIn, String fileOut) {
        try {
            FileInputStream fis = new FileInputStream(new File(fileIn));
            FileOutputStream fos = new FileOutputStream(new File(fileOut));
            int chars = 0;
            StringBuffer tmpStrLine = null;
            int nbCase = 0;
            int processedCase = 1;
            int guide = 0;
            while ((chars != -1) && ((nbCase == 0) || (processedCase <= nbCase))) {
                tmpStrLine = new StringBuffer();
                while (((chars = fis.read()) != -1) && (((char) chars) != '\n')) {
                    tmpStrLine.append((char) chars);
                }
                if (guide == 0) { // searching for nbCase
                    nbCase = Integer.parseInt(tmpStrLine.toString());
                    guide = 1;
                } else if (guide == 1) { // process
                    // init
                    //System.out.println("IN : " +tmpStrLine.toString());
                    String[] tmp = tmpStrLine.toString().split("\\s");
                    int bottomLimit = Integer.parseInt(tmp[0]);
                    int topLimit = Integer.parseInt(tmp[1]);
                    int nbRecycledPair = 0;
                    for (int processedNumber = bottomLimit; processedNumber <= topLimit; processedNumber++) {
                        char[] numberElmt = (""+processedNumber).toCharArray();
                        int numberElmtLength = numberElmt.length;
                        if (numberElmtLength > 1) {
                            for (int j = 0; j < (numberElmtLength-1); j++) {
                                char lastElmt = numberElmt[numberElmtLength-1];
                                for (int k = (numberElmtLength-1); k > 0; k--) {
                                    numberElmt[k] = numberElmt[k-1];
                                }
                                numberElmt[0] = lastElmt;
                                int tmpRecycle = Integer.parseInt(String.valueOf(numberElmt, 0, numberElmtLength));
                                if (tmpRecycle > processedNumber && tmpRecycle <= topLimit) {
                                    nbRecycledPair++;
                                }
                            }
                        }
                    }
                    // output result
                    fos.write(("Case #"+processedCase+": "+nbRecycledPair+"\n").getBytes());
                    //System.out.println("Case #"+processedCase+": "+nbRecycledPair);
                    // back to search tmpCredit
                    processedCase++;
                }
            }
            fis.close();
            fos.close();
        } catch (FileNotFoundException e) {
            System.err.println("FileNotFound : " + e);
        } catch (IOException e) {
            System.err.println("IOException : " + e);
        } catch (Exception e) {
            System.err.println("Other Exception : " + e);
        }
    }

    /**
     * @param args the command line arguments
     **/
    public static void main(String[] args) {
        // TODO code application logic here
        recycledNumbers("C-small-attempt0.in", "C-small-attempt0.out");
    }
}
