Limits 2s, 512 MB

A number is a "Noora" number if the count of distinct digits of the number is equal to the maximum digit of the number. So, 123 is a Noora number but 124 is not. Some of the first Noora numbers are 1, 11, 12, 20, 21, 103, 111, 112, ....

Given nn, you have to tell how many Noora numbers are smaller or equal to nn.

Input

Input starts with an integer TT (1T1000001 ≤ T ≤ 100000), denoting the number of test cases. Each case contains an integer nn (1n10181 ≤ n ≤ 10^{18}).

Output

For each test case, output the number of Noora numbers that are smaller or equal to nn.

Sample

InputOutput
5
10
100
1000
10000
100000
1
5
29
213
1893

Submit

Login to submit.

Statistics

82% Solution Ratio
partha_mbstuEarliest, May '18
Sahil.764169Fastest, 0.0s
mh755628Lightest, 1.0 MB
serotoninShortest, 766B
Toph uses cookies. By continuing you agree to our Cookie Policy.