- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
Niloufar wants to give Amin a gift after counting his birth date in calendar from begining. Help Niloufar to solve this problem.

You are given two integers \(m\) and \(n\) and finds the \(n\)-th smallest natural number that contains the number \(m\) as a subsequence.
We know that the number \(m\) consists of distinct digits.
ورودی
The first line of input contains a positive integer \(t\), representing the number of test cases.
\[1 \leq t \leq 100\]
In the first line of each test case, two positive integer \(m\) and \(n\) is given in order.
\[1 \leq m \leq 5000\] \[1 \leq n \leq 10^{12}\]
خروجی
For each test case, print a single integer representing the \(n\)-th smallest number that contains \(m\) as a subsequence.
مثالها
ورودی نمونه ۱
3
21 14
1403 1
2189 100
خروجی نمونه ۱
221
1403
201689
ارسال پاسخ برای این سؤال