import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class RecycledNumbers{
	
	
	
	int getcount(int small,int large){
		int count = 0;
		for(int currnum = small; currnum < large; currnum++){
			int permut = currnum;
			int no_of_digits = 0;
			while(permut > 0){
				permut = permut/10;
				no_of_digits++;
			}
			int lastDigit = currnum % 10;
			permut = currnum / 10;
			permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
			while(permut != currnum){
				
				if(permut >= currnum && permut <= large){
					
					count++;
				}
				lastDigit = permut % 10;
				permut = permut / 10;
				permut = permut + lastDigit * (int)Math.pow(10, no_of_digits-1);
				
			}
			
		}
		
		return count;
	}
	
	public static void main(String args[]){
		RecycledNumbers d = new RecycledNumbers();
		
		int no_of_cases = 0;
		String input = "";
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
			no_of_cases = Integer.parseInt(br.readLine());
		}
		catch(Exception e){
			System.out.println("First line is not a number");
		}
		
		for(int i=1; i <= no_of_cases;i++){
			try{
				input = br.readLine();
			}
			catch(Exception e){
				System.out.println("Number of test cases different from the number mentioned in first line");
			}
			
			System.out.print("Case #" +i+": ");
			
			StringTokenizer t =  new StringTokenizer(input);
			int small=0,large=0;
			if(t.hasMoreTokens()){
				small = Integer.parseInt(t.nextToken());
			}
			if(t.hasMoreTokens()){
				large = Integer.parseInt(t.nextToken());
			}
			System.out.println(d.getcount(small,large));
			
		}
		
		
		

	}
	
	
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package codejam.qualification.recyclednumbers;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import util.BaseResolver;
import util.Util;

/**
 *
 * @author bohmd
 */
public class RecycledNumbers extends BaseResolver {

    int cases;

    public static void main(String[] args) throws Exception {
        if (args.length == 0 || args[0].equals("")) {
            throw new Exception("The first parameter must be the input file name without extension.");
        } else {
            new RecycledNumbers(args[0]).resolve();
        }
    }

    public RecycledNumbers(String file) {
        super(file);
    }

    @Override
    protected void executeLine(String line) throws Exception {
        if (getLineNum() == 0) {
            cases = Util.getInt(line);
        } else {
            List<Integer> lineCase = Util.getIntList(line);
            write(resolveCase(lineCase.get(0), lineCase.get(1)));
        }
    }
    
    protected String resolveCase(int min, int max) {
        Set<Pair> pairSet= new HashSet<Pair>();
        for(int i=min; i<=max; i++)
        {
            String n = i+"";
            for(int j=0; j<n.length(); j++)
            {
                String m = n.substring(j)+n.substring(0,j);
                int mInt=Integer.parseInt(m);
                if(mInt>i && mInt<=max)
                {
                    pairSet.add(new Pair(i, mInt));
                }
            }
        }
        return " "+pairSet.size();
    }
    
    private class Pair
    {
        int m;
        int n;

        public Pair(int n, int m) {
            this.m = m;
            this.n = n;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Pair other = (Pair) obj;
            return (this.n == other.n && this.m == other.m) || (this.n == other.m && this.m == other.n);
        }

        @Override
        public int hashCode() {
            int hash = 7;
            hash = 11 * hash + this.m + this.n;
            return hash;
        }
    }
}
