Special Number

3.3

3 votes
Problem

Problem Statement

A Positive number n will be called special if all the digits of the number are the same. For example, 4,5 & 11 are special numbers but 123,2019 are not special numbers.

For a given number n, find the number of special numbers from 1 to n. Both 1 and n are inclusive

Input

The first line contains one integer t (1≤t≤104). Then t test cases follow.

Each test case is characterized by one integer n (1≤n≤109).

Output

For each test case output the number of special numbers from 1 to n. Both 1 and n are inclusive.

Sample Input
6
1
2
3
4
5
50
Sample Output
1
2
3
4
5
13
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

All numbers that are Special Number in range of 50 are (1,2,3,4,5,6,7,8,9,11,22,33,44).

Contributers:
Editor Image

?