cswork / OAOpen practice workspace

BloombergOA #2

Ashley Loves Numbers (Financial Engineer)

Estimated MediumJudge-ready

Topics (AI-labelled)Prefix & RangesBits & Math

For each closed interval [n,m], count the positive integers whose decimal representation has all distinct digits. 0 is a digit too, and appearing twice counts as a repeat; no leading zeros are added.

Input

This site's simplified input protocol: the first line contains q, followed by q lines each with two integers n m (the fixed column count 2 of the original function wrapper is omitted). 1≤q≤100000, 1≤n≤m≤1000000.

Output

Output one count per line, in query order.

Example 1

Input:

2
1 20
11 11

Output:

19
0

Example 2

Input:

2
98 102
100 100

Output:

2
0

Example 3

Input:

3
1 9
10 10
123 123

Output:

9
1
1

Example notes

From 1 to 20 only 11 is invalid, giving 19; from 98 to 102 only 98 and 102 are valid; the single points 10 and 123 are both valid, while 100 is invalid because 0 repeats.

Editorial

Loading solution…