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;
	}
}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

public class RecycledNumbers {

    public static int recycle(int source, int digits) {
        int pow = (int) Math.pow(10, digits - 1);
        int mod = source % 10;
        return pow * mod + source / 10;
    }

    public static class Range {
        public final int A;
        public final int B;

        public Range(int A, int B) {
            this.A = A;
            this.B = B;
        }
    }

    public static Iterator<Range> iterator(Readable input) {
        final Scanner scanner = new Scanner(input);

        return new Iterator<Range>() {
            private int cases = scanner.nextInt();

            @Override
            public boolean hasNext() {
                return cases > 0;
            }

            @Override
            public Range next() {
                int A = scanner.nextInt();
                int B = scanner.nextInt();

                cases--;
                return new Range(A, B);
            }

            @Override
            public void remove() {
                throw new AbstractMethodError();
            }
        };
    }

    public static int recycledPairs(Range scores) {
        int digits = Integer.toString(scores.A).length();
        HashSet<String> pairs = new HashSet<String>();
        for (int i = scores.A; i <= scores.B; i++) {
            int recycled = recycle(i, digits);
            while (recycled != i) {
                if (recycled >= scores.A && recycled <= scores.B) {
                    int first = i < recycled ? i : recycled;
                    int second = i > recycled ? i : recycled;

                    pairs.add(String.format("%d%d", first, second));
                }
                recycled = recycle(recycled, digits);
            }
        }

        return pairs.size();
    }

    public static void main(String[] args) throws FileNotFoundException {
        FileReader fileReader = new FileReader(args[0]);

        int caseId = 1;
        Iterator<Range> iterator = iterator(fileReader);

        while (iterator.hasNext()) {
            int result = recycledPairs(iterator.next());
            System.out.format("Case #%s: %s\n", caseId, result);
            caseId++;
        }
    }
}
