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.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class C {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public long number(String s, int allowed, boolean flag) {
		if (s.length() == 0) {
			return 1;
		}
		if (allowed == 0) {
			return 1;
		}
		long ans = 0;
		if (!flag) {
			if (s.charAt(0) != '0') {
				for (int i = 0; i <= allowed; i++) {
					ans += numb[s.length() - 1][i];
				}
			} else {
				return number(s.substring(1), allowed, false);
			}
		}
		for (int i = 1; i <= allowed; i++) {
			ans += (s.charAt(0) - '1') * numb[s.length() - 1][i - 1];
		}
		allowed--;
		return ans + number(s.substring(1), allowed, false);
	}

	long[][] numb = new long[19][4];

	public void solve() {
		int q = in.nextInt();
		numb[0][0] = 1;
		for (int i = 1; i < numb.length; i++) {
			numb[i][0] = 1;
			numb[i][1] = 9 * i;
			numb[i][2] = 9 * 9L * i * (i - 1) / 2;
			numb[i][3] = 9L * 9 * 9 * (i - 1) * (i - 2) * (i - 3) / 6;
		}
		for (int t = 0; t < q; t++) {
			long l = in.nextLong();
			long r = in.nextLong();
			int lenl = (l + "").length();
			int lenr = (r + "").length();
			long ans = 0;
			for (int i = lenl; i < lenr; i++) {
				ans += (numb[i - 1][2] + numb[i - 1][1] + numb[i - 1][0]) * 9;
			}
			String sl = l + "";
			String sr = r + "";
			int th = 0;
			for (int i = 0; i < sl.length(); i++) {
				if (sl.charAt(i) != '0') {
					th++;
				}
			}
			if (th <= 3) {
				ans++;
			}
//			System.out.println(ans + " " + number(sr, 3, true) + " " + number(sl, 3, true));
			ans += number(sr, 3, true) - number(sl, 3, true);
			out.println(ans);
		}
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("segments.in"));
				out = new PrintWriter(new File("segments.out"));
			}
			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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