G - Birth Date


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Niloufar wants to give Amin a gift after counting his birth date in calendar from begining. Help Niloufar to solve this problem.

Date

You are given two integers mm and nn and finds the nn-th smallest natural number that contains the number mm as a subsequence.

We know that the number mm consists of distinct digits.

ورودی🔗

The first line of input contains a positive integer tt, representing the number of test cases.

1t1001 \leq t \leq 100

In the first line of each test case, two positive integer mm and nn is given in order.

1m50001 \leq m \leq 5000 1n10121 \leq n \leq 10^{12}

خروجی🔗

For each test case, print a single integer representing the nn-th smallest number that contains mm as a subsequence.

مثال‌ها🔗

ورودی نمونه ۱🔗

3
21 14
1403 1
2189 100
Plain text

خروجی نمونه ۱🔗

221
1403
201689
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.