import java.util.Scanner;
import java.io.*;
import java.lang.Math;


public class C{
	public static int recycle(String str){
		String[] numbers = str.split(" ");
		int min = Integer.parseInt(numbers[0]);
		int max = Integer.parseInt(numbers[1]);
		int ret = 0;

		for(int i = min; i < max; i++){
			String num = i + "";
			int len = num.length();
			int k = i;
			for(int j = 1; j < len; j++){
				k = (k/10) + (int)java.lang.Math.pow(10.0,(double)(len-1))*(k%10);
				if (k > i && k <= max)
					ret++;
				else if(k == i)
					break;
			}
		}

		return ret;
	}

	public static void main(String[] args){
		Scanner sc = null;
		String next;
		int out;
		try{
			sc = new Scanner(new File("C-large.in"));
			int cases = Integer.parseInt(sc.nextLine());
			int current = 0;
			

			FileWriter fs = new FileWriter("output.txt");
			BufferedWriter buff = new BufferedWriter(fs);
			while(current < cases){
				next = sc.nextLine();
				current++;
				out = recycle(next);
				buff.write("Case #" + current + ": " + out + "\n");
			}
			buff.close();
		}
		catch(Exception ex){}
	}
}
package jp.funnything.competition.util;

import java.util.Iterator;

/**
 * Do NOT change the element in iteration
 */
public class Combination implements Iterable< int[] > , Iterator< int[] > {
    private final int _n;
    private final int _k;
    private int[] _data;

    public Combination( final int n , final int k ) {
        if ( k < 0 || k > n ) {
            throw new IllegalArgumentException();
        }

        _n = n;
        _k = k;
    }

    @Override
    public boolean hasNext() {
        return _data == null || _data.length > 0 && _data[ 0 ] < _n - _k;
    }

    @Override
    public Iterator< int[] > iterator() {
        return this;
    }

    @Override
    public int[] next() {
        if ( _data == null ) {
            _data = new int[ _k ];
            for ( int index = 0 ; index < _k ; index++ ) {
                _data[ index ] = index;
            }
        } else {
            int i = 0;

            while ( i < _k - 1 && _data[ i + 1 ] == _data[ i ] + 1 ) {
                _data[ i ] = i++;
            }

            _data[ i ]++;
        }

        return _data;
    }

    @Override
    public void remove() {
    }
}
