Problem: Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not.

You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R.

Each testcase contains several segments, for each of them you are required to solve the problem separately.

Input

The first line contains a single integer T (1 ≤ T ≤ 10^4) — the number of segments in a testcase.

Each of the next T lines contains two integers L_i and R_i (1 ≤ L_i ≤ R_i ≤ 10^{18}).

Output

Print T lines — the i-th line should contain the number of classy integers on a segment [L_i; R_i].

Example

Input

4
1 1000
1024 1024
65536 65536
999999 1000001


Output

1000
1
0
2

Solution (in JAVA):

Solution:
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			System.out.println(getCount(a, b));
		}
		sc.close();
	}

	private static long getCount(long a, long b) {
		if(b <= 1000) {
			return b-a+1;
		}
		long infix = 0;
		if(a <= 1000) {
			infix = 1000-a+1;
			a = 1001;
		}
		
		String str1 = a+"";
		String str2 = b+"";
		if(str2.length() == str1.length()) {
			return infix+getCountSam(str1, str2, 3);
		}
		else {
			long fix = infix+getCountSamHigh(str1, 3)+getCountSamLow1(str2, 3);
			return fix+getCountMid(str1.length()+1, str2.length()-1);
		}

	}

	/**
	 * 0000... ~ 9999... (��n����λ)
	 * @param n  ��λ
	 * @param k  ѡȡ�ı仯���ĸ���
	 * @return
	 */
	private static long getMid(int n, int k) {
		if(k == 1) {
			return 1+n*9l;
		}
		return 1+n*9l+n*(n-1)/2*81l;
	}

	private static long getCountSam(String str1, String str2, int k) {
		if(str1.length() == 1 && str2.length() == 1) {
			return str2.charAt(0)-str1.charAt(0)+1;
		}
		if(k == 1) {
			if(str1.charAt(0) != '0') {
				long ret = str2.charAt(0)-str1.charAt(0);
				if(isNeat(str1)) {
					ret++;
				}
				return ret;
			}
			else {
				if(str2.charAt(0) == '0') {
					return getCountSam(str1.substring(1), str2.substring(1), 1);
				}
				else {
					return (str2.charAt(0)-'0')+getCountSamHigh(str1.substring(1), 1);
				}
			}
		}
		
		if(str1.charAt(0) != '0') {
			if(str1.charAt(0) == str2.charAt(0)) {
				return getCountSam(str1.substring(1), str2.substring(1), k-1);
			}
			else {
				long mid = (str2.charAt(0)-str1.charAt(0)-1)*getMid(str1.length()-1, k-1);
				return getCountSamHigh(str1.substring(1), k-1)+mid+getCountSamLow(str2.substring(1), k-1);
			}
		}
		else {
			if(str1.charAt(0) == str2.charAt(0)) {
				return getCountSam(str1.substring(1), str2.substring(1), k);
			}
			else {
				long mid = (str2.charAt(0)-str1.charAt(0)-1)*getMid(str1.length()-1, k-1);
				return getCountSamHigh(str1.substring(1), k)+mid+getCountSamLow(str2.substring(1), k-1);
			}
		}
	}

	private static long getCountSamLow1(String str, int k) {
		StringBuilder sb = new StringBuilder();
		sb.append('1');
		for(int i = 1; i < str.length(); i++) {
			sb.append("0");
		}
		return getCountSam(sb.toString(), str, k);
	}
	
	private static long getCountSamLow(String str, int k) {
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < str.length(); i++) {
			sb.append('0');
		}
		return getCountSam(sb.toString(), str, k);
	}

	private static long getCountSamHigh(String str, int k) {
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < str.length(); i++) {
			sb.append('9');
		}
		return getCountSam(str, sb.toString(), k);
	}

	private static boolean isNeat(String str) {
		for(int i = 1; i < str.length(); i++) {
			if(str.charAt(i) != '0') {
				return false;
			}
		}
		return true;
	}

	private static long getCountMid(int size1, int size2) {
		long sum = 0;
		for(int i = size1; i <= size2; i++) {
			sum += 9*(1+9l*(i-1)+81l*(i-1)*(i-2)/2);
		}
		return sum;
	}

}