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.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;


public class CodeJamQ3 {

  public static String[] read(final String name) throws IOException {
    final InputStreamReader reader = new FileReader(new File(name));
    final char[] buf = new char[1024];
    int count = 0;
    final StringBuilder res = new StringBuilder();
    do {
      count = reader.read(buf);
      if (count > 0)
      res.append(buf, 0, count);
    } while (count != -1);
    return res.toString().trim().split("(\\r?\\n)+");
  }

  public static void main(final String[] args) throws Exception {
    final String[] input = read("C-small-attempt0.in");
    final FileWriter out = new FileWriter("out");

    final int casesCount = Integer.parseInt(input[0]);
    for (int caseN = 1; caseN <= casesCount; caseN++) {
      final String[] data = input[caseN].split("\\s+");
      final int a = Integer.parseInt(data[0]);
      final int b = Integer.parseInt(data[1]);

      out.write("Case #" + caseN + ": " + solve(a, b) + "\n");

    }

    out.close();
  }

  private static long solve(final int a, final int b) {
    long count = 0;
    final HashSet<Tuple> check= new HashSet<Tuple>();
    for (int x = a; x <= b; x++) {
      final String s = String.valueOf(x);
//      int k = 0;
//      int equal = 0;
      for (int i = 1; i < s.length(); i++) {
        final int test = Integer.parseInt(s.substring(i) + s.substring(0, i));
        if (test <= b && test >= a && test > x) {
          final Tuple t = new Tuple(x, test);
          if (check.contains(t)) { continue; }
          check.add(t);
          ++count;
          System.out.println(x + " - "+ test);
        }

//        if (s.charAt(i) == s.charAt(i - 1)) { ++equal; }
//        if (s.charAt(0) <= s.charAt(i) && s.charAt(i) != '0') {
//          final int test = Integer.parseInt(s.substring(i) + s.substring(0, i));
//          if (b >= test) { ++k; }
//        }
      }
//      if (equal < s.length() - 1) { count += k; }
    }
    return count;
  }

  private static class Tuple {
    int x, y;
    Tuple(final int x, final int y) {this.x = x; this.y = y; }
    @Override
    public int hashCode() {
      return x + y;
    }
    @Override
    public boolean equals(final Object obj) {
      final Tuple t = (Tuple)obj;
      return t.x == x && t.y == y || t.x == y && t.y ==x;
    }
  }

}
