import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

//	static int MAX = 10000;
	static int MAX = 2000000;
	static Object[] All = new Object[MAX+1];
	
	static int size( int x ) {
		if(x>999999) return 7;
		if(x>99999)  return 6;
		if(x>9999)   return 5;
		if(x>999)    return 4;
		if(x>99)     return 3;
		if(x>9)      return 2;
		return 1;
	}
	static int[] rotate( int value ) {
		List<Integer> result = new ArrayList<Integer>();
		int[] V = new int[8];
		int s = size(value);
		int x = value;
		
		for(int i=s-1;i>=0;i--) {
			V[i] = x%10;
			x /=10;
		}
		int rot;
		for(int i=1; i<s; i++) {
			if(V[i]!=0){
				rot=0;
				for(int j=0,ii=i;j<s; j++,ii=(ii+1)%s){
					rot=rot*10+V[ii];
				}
				if(rot>value && !result.contains(rot))
					result.add(rot);
			}
		}
		if( result.isEmpty() )
			return null;
		int[] r = new int[result.size()];
		for(int i=0; i<r.length; i++)
			r[i]=result.get(i);
		return r;
	}
	
	static void precalculate() {
		for(int i=1; i<=MAX; i++){
			All[i] = rotate(i);
		}
	}
	static int solve( Scanner in ) {
		int A, B, sol=0;
		
		A = in.nextInt();
		B = in.nextInt();

		for( int i=A; i<=B; i++) {
//			List<Integer> result = rotate(i);
			if( All[i]!=null ) {
				for(int value: (int[])All[i] ) {
					if( value <= B )
						sol++;
				}
			}
		}

		return sol;
	}
	
	public static void main ( String args[] ) {
		int T; 
		Scanner in = new Scanner(System.in);
		T = in.nextInt();
		int cnt=0;
		int sol;
		precalculate();
		for( cnt=1; cnt<=T; cnt++ ) {
			sol = solve( in );
			System.out.printf("Case #%d: %d\n", cnt, sol);
		}

	}
}

package Qual;
import java.io.*;
import java.math.*;
import java.util.*;


public class C {
	static void start() throws IOException {
		new C().run1();
	}
	
	private final String dir = "D:\\contest\\gcj\\2012\\" + getClass().getPackage().toString().split(" ")[1] + "\\" + getClass().getSimpleName();
//	private final String inputFileName = "sample.txt";
	private final String inputFileName = "C-large.in";
	private final String outputFileName = "res.txt";

	int A, B;
	final Set<Integer> st = new HashSet<Integer>();
	int pair(int v) {
		if(st.contains(v)) {
			return 0;
		}
		
		int res = 0;
		String s = v + "";
		for(int i = 0; i < s.length(); i++) {
			s = s.charAt(s.length() - 1) + s.substring(0, s.length() - 1);
			if(s.charAt(0) != '0') {
				final int x = Integer.parseInt(s);
				if(A <= x && x <= B && !st.contains(x)) {
					st.add(x);
					res++;
				}
			}
		}
		return res * (res - 1) / 2;
	}
	
	final int MAX = 2000000;
	boolean[] visited = new boolean[MAX * 10];
	int dfs(int x, int d) {
		if(d == 0) {
//			System.err.println(x + " " + pair(x));
			return pair(x);
		}

		if(st.contains(x)) {
			return 0;
		}
		pair(x);
		
		int res = 0;
		for(int i = 0; i <= 9; i++) {
			if(x != 0 || i != 0) {
				res += dfs(x * 10 + i, d - 1);
			}
		}
		return res;
	}
	
	void run() throws IOException {
		int T = IOFast.nextInt();
		while(T-- != 0) {
			A = IOFast.nextInt();
			B = IOFast.nextInt();
			st.clear();
			int res = 0;
			for(int i = A; i <= B; i++) {
				if(!st.contains(i)) {
					res += pair(i);
				}
			}
			printCase();
			IOFast.out.println(res);
			IOFast.out.flush();
		}
	}

	void run1() throws IOException {
		IOFast.setReader(new FileReader(dir + "\\" + inputFileName));
		IOFast.setWriter(new FileWriter(dir + "\\" + outputFileName));
		run();
	}
	
	private static int CASE;
	private static void printCase() {
		IOFast.out.print("Case #" + ++CASE + ": ");
	}
	
	public static void main(String[] args) throws IOException {
		start();
		IOFast.out.flush();
		IOFast.in.close();
		IOFast.out.close();
	}

	static
	public class IOFast {
		private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		private static PrintWriter out = new PrintWriter(System.out);

		//	private static final int BUFFER_SIZE = 50 * 200000;
		private static final StringBuilder buf = new StringBuilder();
		private static boolean[] isDigit = new boolean[256];
		private static boolean[] isSpace = new boolean[256];

		static {
			for(int i = 0; i < 10; i++) {
				isDigit['0' + i] = true;
			}
			isDigit['-'] = true;
			isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
		}

		static boolean endInput;
		
		public static void setReader(Reader r) { in = new BufferedReader(r); }
		public static void setWriter(Writer w) { out = new PrintWriter(w); }

		private static int nextInt() throws IOException {
			boolean plus = false;
			int ret = 0;
			while(true) {
				final int c = in.read();

				if(c == -1) {
					endInput = true;
					return Integer.MIN_VALUE;
				}

				if(isDigit[c]) {
					if(c != '-') {
						plus = true;
						ret = c - '0';
					}
					break;
				}
			}

			while(true) {
				final int c = in.read();
				if(c == -1 || !isDigit[c]) {
					break;
				}
				ret = ret * 10 + c - '0';
			}

			return plus ? ret : -ret;
		}

		private static long nextLong() throws IOException {
			boolean plus = false;
			long ret = 0;
			while(true) {
				final int c = in.read();

				if(c == -1) {
					endInput = true;
					return Integer.MIN_VALUE;
				}

				if(isDigit[c]) {
					if(c != '-') {
						plus = true;
						ret = c - '0';
					}
					break;
				}
			}

			while(true) {
				final int c = in.read();
				if(c == -1 || !isDigit[c]) {
					break;
				}
				ret = ret * 10 + c - '0';
			}

			return plus ? ret : -ret;
		}



		private static String next() throws IOException {
			buf.setLength(0);

			while(true) {
				final int c = in.read();

				if(c == -1) {
					endInput = true;
					return "-1";
				}

				if(!isSpace[c]) {
					buf.append((char)c);
					break;
				}
			}

			while(true) {
				final int c = in.read();

				if(c == -1 || isSpace[c]) {
					break;
				}
				buf.append((char)c);
			}

			return buf.toString();
		}

		private static double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

	}
}
