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.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeMap;

public class C {
	public static void main(String[] args) throws Exception {
		Scanner in = new Scanner(System.in);
		int q = in.nextInt();
		long l = 0, r = 0, z = 0;
		ArrayList<Long> pos = new ArrayList<Long>();
		TreeMap<Long, Long> mark = new TreeMap<Long, Long>();
		for (int a = 0; a < 18; a++) {
			for (int b = 0; b < a; b++) {
				for (int c = 0; c < b; c++) {
					for (int i = 0; i < 10; i++) {
						for (int j = 0; j < 10; j++) {
							for (int k = 0; k < 10; k++) {
								z = (long) ((long) (i * Math.pow(10, a)) + (long) (j * Math.pow(10, b)) + (long) (k * Math.pow(10, c)));
								if (mark.get(z) == null) {
									pos.add(z);
									mark.put(z, (long) 0);
								}
							}
						}
					}
				}
			}
		}
		Collections.sort(pos);
		pos.add((long) Math.pow(10, 18));
		int n = pos.size(), x = 0, y = 0;
		for (int i = 0; i < q; i++) {
			l = in.nextLong();
			r = in.nextLong();
			if ((l > pos.get(n-1) && r > pos.get(n-1))
					|| (l < pos.get(0) && r < pos.get(0))) {
				System.out.println(0);
				continue;
			}
			if (l > pos.get(n-1)) {
				l = pos.get(n-1);
			}
			if (r > pos.get(n-1)) {
				r = pos.get(n-1);
			}
			if (l < pos.get(0)) {
				l = pos.get(0);
			}
			if (r < pos.get(0)) {
				r = pos.get(0);
			}
			x = lower_bound(pos, l);
			y = lower_bound(pos, r);
			//System.out.println(x + " " + y);
			if (l != pos.get(x) && r != pos.get(y)) {
				System.out.println(y - x);
				continue;
			}
			if (l != pos.get(x)) {
				x--;
				System.out.println(y - x);
				continue;
			}
			if (r != pos.get(y)) {
				y--;
				System.out.println(y - x + 1);
				continue;
			}
			System.out.println(y - x + 1);
		}
		in.close();
	}

	public static int lower_bound(ArrayList<Long> arr, Long key) {
		int len = arr.size();
		int lo = 0;
		int hi = len - 1;
		int mid = (lo + hi) / 2;
		while (true) {
			long cmp = arr.get(mid).compareTo(key);
			if (cmp == 0 || cmp > 0) {
				hi = mid - 1;
				if (hi < lo)
					return mid;
			} else {
				lo = mid + 1;
				if (hi < lo)
					return mid < len - 1 ? mid + 1 : -1;
			}
			mid = (lo + hi) / 2;
		}
	}
}