406596: GYM102452 D Defining Labels
Description
Microsoft Excel is a spreadsheet developed by Microsoft. It features calculation, graphing tools, pivot tables, and a macro programming language called Visual Basic for Applications. It has been a very widely applied spreadsheet for many different operating systems, especially since version 5 in 1993, and it has replaced Lotus 1-2-3 as the industry standard for spreadsheets.
In Excel, the labelling for columns uses upper case letters instead of numbers to distinguish it from the labelling for rows. The first column in Excel is labelled $$$A$$$, the second is labelled $$$B$$$ and so on. And after column $$$Z$$$, the next columns are labelled $$$AA, AB, \cdots, ZZ, AAA,\cdots$$$.
In this problem, we'll define a new labelling scheme. Let's use numerical digits instead of letters, and only a subset of the digits. Let's define base $$$k \ (2 \le k \le 10)$$$ labelling as using only digits from $$$10 - k$$$ to $$$9$$$ in the labels. For example, the labels in base $$$10$$$ in ascending order are $$$0, 1, \cdots , 9, 00, 01, \cdots$$$, and in base $$$7$$$ they are $$$3, 4, \cdots, 9, 33, 34,\cdots$$$.
Now, given $$$k$$$ and $$$X$$$, your task is to find the $$$X$$$-th label in base $$$k$$$.
InputThe input contains multiple cases. The first line of the input contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^5$$$), the number of cases.
For each case, the first line of the input contains a single integer $$$k$$$ ($$$2 \leq k \leq 10$$$), the base of the labelling scheme. The second line contains a single integer $$$X$$$ ($$$1 \leq X \leq 10^9$$$), the number of the label you need to find.
OutputFor each case, print a single string in a single line, the $$$X$$$-th label.
ExampleInput2 10 10 5 10Output
9 59