Ritesh has found out a keyboard from his store room which is very unique. Unique because the keyboard contains only 10 keys (the numpad). In other words the keyboard has 10 keys, they are 1,2,3,4,5,6,7,8,9,0.

Sharat has got the task to type all the** **natural number from **1 **to **N**, using this keyboard. But the keyboard is in damaged condition, means, after pressing **M** keys in total from the keyboard, the keyboard completely stops working.Now you being his friend need to find out the greatest natural number he can type using the keyboard starting from **1**. (You need to find the value of **N**).

**Input:**

The first line of input contains the integer **T**, where **T** is the number of test cases. Then T test cases follow. Each test case contains an integer **M, **where** ****M** is maximum number of keys he can press in the keyboard before its completely damaged.

**Output:**

In each test case print a single integer **N,**where** N **is the greatest natural number he can type using the keyboard starting from **1**.

**Constraints:**

0 < T < 10^{5}

0 < M < 38890

**Example:**

**Input:**

3

5

10

15

**Output:**

5

9

12

**Explanation:**

(i)For the 1st test case **M=5**, he can type **1 2 3 4 5**. Now after pressing **5 **keys the keyboard is damaged.

(ii)For the 2nd test case **M=10**, he can type **1 2 3 4 5 6 7 8 9**, he has pressed **9 **keys and can press only **1 **more key but the next natural number he needs to type is **10**, which is 2 digit, so he cant type **10**, thus the greatest natural number he can type starting from **1 **is **9.**

(iii)For the 3rd test case **M=15**, he can type **1 2 3 4 5 6 7 8 9 10 11 12**, now he has pressed **15** keys and the keyboard is damaged. Thus the greatest natural number he can type starting from **1 **is **12****.**

Author: animesh7995

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.