import java.util.HashSet;
import java.util.Scanner;

public class C {

	static HashSet p = new HashSet();
	static int low;
	static int high;
	int count = 0;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int no = sc.nextInt();

		for (int i = 1; i <= no; i++) {

			p.clear();
			low = sc.nextInt();
			high = sc.nextInt();

			for (int l = low; l <= high; l++) {
				recycle(l);
			}
			System.out.println("Case #" + i + ": " + p.size());

		}
	}

	public static void recycle(int no) {

		String s = Integer.toString(no);
		for (int i = 0; i < s.length(); i++) {
			String rec = s.substring(i) + s.substring(0, i);
			int r = Integer.parseInt(rec);
			if (r != no && r >= low && r <= high) {
				int min = Math.min(r, no);
				int max = Math.max(r, no);
				String a = Integer.toString(min) + "" + Integer.toString(max);
				p.add(a);

			}
		}

	}
}

package com.jagsaund.codejam.qualifcation;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class RecycledNumbers {
  public RecycledNumbers() {
    
  }
  
  public String run(String line) {
    int m;
    int n;
    
    StringTokenizer tokenizer = new StringTokenizer(line);
    
    n = Integer.parseInt(tokenizer.nextToken());
    m = Integer.parseInt(tokenizer.nextToken());
    
    Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
    
    for (int i=0; i<=(m-n); i++) {
      String value = Integer.toString((i+n));
//      System.out.println("current value: " + value);
      
      if (!map.containsKey((i+n))) {
        map.put((i+n), new HashSet<Integer>());
      }
      
      for(int j=1; j<value.length(); j++) {
        value = value.substring(1) + value.charAt(0);
//        System.out.println("rotated value: " + value);
        
        int rotatedNumber = Integer.parseInt(value);
        
        if (rotatedNumber >= n && rotatedNumber <= m && rotatedNumber != (i+n)) {
          if (map.containsKey(rotatedNumber)) {
            
          } else {
            Set<Integer> set = map.get((i+n));
            set.add(rotatedNumber);
            map.put((i+n), set);
            
//            System.out.println("Added: " + rotatedNumber);
//            System.out.println("Current pairs: " + set.size());
          }
        }
    
      }
    }
    
    int count = 0;
    Set<Integer> keys = map.keySet();
    for (Iterator<Integer> it = keys.iterator(); it.hasNext();) {
      count += map.get(it.next()).size();
    }
    
    return count + "";
  }
}
