/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;

/**
 *
 * @author imgps
 */
public class C {
    public static void main(String args[]) throws Exception{
        int A,B;
        int ctr = 0;
        int testCases;
        
        Scanner sc = new Scanner(new FileInputStream("C-small-attempt0.in "));
        testCases = sc.nextInt();
        int input[][] = new int[testCases][2];
        for(int i=0;i<testCases;i++)
        {
          //  System.out.print("Enter input A B: ");
            input[i][0] = sc.nextInt();
            input[i][1] = sc.nextInt();
            
        }
  

for(int k=0;k<testCases;k++){
      ctr = 0;
      A = input[k][0];
      B = input[k][1];
        for(int i = A;i<=B;i++){
            int num = i;
            int nMul = 1;
            int mul = 1; 
            int tnum = num/10;
            while(tnum > 0){
                mul = mul *10;
                tnum= tnum/10;
            }
            tnum = num;
            int n = 0;
            while(tnum > 0 && mul >= 10){
                nMul = nMul * 10;
                n = (num % nMul) * mul + (num / nMul);
                mul = mul / 10;
                tnum = tnum / 10;
                for(int m=num;m<=B;m++){
                    
                    if(n == m && m > num){
                        ctr++;
                    }
                }
                
                
                
         
            }
        }
        System.out.println("Case #"+(k+1)+": "+ctr);
        
    }
    }
}



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Pair<L,R> {

	  private final L left;
	  private final R right;

	  public Pair(L left, R right) {
	    this.left = left;
	    this.right = right;
	  }

	  public L getLeft() { return left; }
	  public R getRight() { return right; }

	  @Override
	  public int hashCode() { return left.hashCode() ^ right.hashCode(); }

	  @Override
	  public boolean equals(Object o) {
	    if (o == null) return false;
	    if (!(o instanceof Pair)) return false;
	    Pair pairo = (Pair) o;
	    return this.left.equals(pairo.getLeft()) &&
	           this.right.equals(pairo.getRight()) || this.left.equals(pairo.getRight()) &&
	           this.right.equals(pairo.getLeft());
	  }

	}


public class Dancing {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str = in.readLine();
		int numberOfCases = Integer.parseInt(str);
		ArrayList<Integer> array = new ArrayList<Integer>();
		for (int j = 0; j < numberOfCases; j++) {
			String str1 = in.readLine();
			String delimiter = " ";
			String[] temp;
			temp = str1.split(delimiter);
			String lowerlimit = temp[0];
			String upperlimit = temp[1];
			int count = recycledInteger(upperlimit, lowerlimit);
			array.add(count);
		}
		for (int i = 0; i < array.size(); i++) {
			System.out.println("Case #"+(i+1)+": "+array.get(i));
		}
		

	}

	public static int recycledInteger(String upperlimit, String lowerlimit) {

		int lower = Integer.parseInt(lowerlimit);
		int upper = Integer.parseInt(upperlimit);
		// String.valueOf(i);
		int counter = 0;
		int temp = lower;
		ArrayList<Pair<Integer, Integer>> arraypairs = new ArrayList<Pair<Integer, Integer>>();
		while (temp <= upper) {
			String string = String.valueOf(temp);
			for (int i = 1; i < string.length(); i++) {
				String recycled = string.substring(i, string.length())
						+ string.substring(0, i);
				if (Integer.parseInt(recycled) >= lower
						&& Integer.parseInt(recycled) <= upper) {
					Pair<Integer, Integer> pair = new Pair<Integer, Integer>(
							Integer.parseInt(recycled), temp);
					if (Integer.parseInt(recycled) != temp) {
						if(!arraypairs.contains(pair)){
							//System.out.println(temp+"   "+recycled);
							counter++;
						}
						arraypairs.add(pair);
					}
				}
			}
			temp++;
		}
		return counter;
	}
}
