Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Noora Number

By Matrix.code · 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 number are 1,11,12,20,21,103,111,112, .... .

Given n, you have to tell how many Noora number ≤ n

Input

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

Output

For each test case, output the number of Noora number ≤ n

Sample

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

Discussion

Statistics


85% Solution Ratio

partha_mbstuEarliest, May '18

Sust_desvalidoFastest, 0.1s

mh755628Lightest, 1.0 MB

nstasinShortest, 827B

Submit

Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.