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.*;
import java.util.*;

public class Main implements Runnable {
  Scanner in = new Scanner(System.in);
  HashMap map;
  long[] cnt = new long[2000000];
  
  public Integer[] findPartner(int n) {
    ArrayList<Integer> arr = new ArrayList<Integer>();
    String num = String.valueOf(n);
    for (int i = 1; i < num.length(); i++) {
      String s = num.substring(i);
      s += num.substring(0, i);
      arr.add(Integer.parseInt(s));
    }
    return (Integer[]) arr.toArray(new Integer[arr.size()]);
  }
  
  public void run() {
    int a, b, c, t = in.nextInt();
    long ans;
    
    for (int i = 1; i <= t; i++) {
      a = in.nextInt();
      b = in.nextInt();
      c = 0;
      
      Arrays.fill(cnt, 0);
      map = new HashMap();
      
      for (int j = a; j <= b; j++) {
        if (!map.containsKey(j)) {
          c++;
          Integer[] arr = findPartner(j);
          map.put(j, c);
          for (int k = 0; k < arr.length; k++)
            if (arr[k] >= a && arr[k] <= b)
              map.put(arr[k], c);
        }
      }
      
      for (int j = a; j <= b; j++)
        cnt[(Integer)map.get(j)]++;
      
      ans = 0l;
      for (int j = 1; j <= c; j++)
        ans += (cnt[j] - 1l) * cnt[j] / 2;
      
      System.out.println("Case #" + i + ": " + ans);
    }
  }
  
  public static void main(String[] args) {
    new Thread(new Main()).start();
  }
}