# 2023 Azerbaijan, Semifinals, February 18, 8 - 9 classes

# Lucky numbers

Programmers consider lucky numbers to be the numbers that contain no digits other than **1**, **2**, **4** and **8**. For example, according to programmers, **11**, **8**, **184**, **1248** are lucky numbers, and **147**, **13**, **808** , **555** are not.

Your task is sometimes to find the **k**-th lucky number in ascending order, and sometimes to find the smallest lucky number greater than the given number **k**. Write a program that correctly answers **q** of these two types of queries.

#### Input

The first line contains one integer **q** (**1** ≤ **q** ≤ `10`

) - the number of queries, and each of the following ^{4}**q** lines contains two integers `t`

(_{i}`t`

= {_{i}**1**, **2**}) and `k`

. If _{i}`t`

= _{i}**1** then find the `k`

-th lucky number in ascending order, and if _{i}`t`

= _{i}**2** then find the smallest lucky number greater than `k`

. It is known that:_{i}

- if
`t`

=_{i}**1**then**1**≤`k`

≤_{i}**2***`10`

,^{9} - if
`t`

=_{i}**2**then**0**≤`k`

≤_{i}`10`

.^{15}

#### Output

For each query, print the answer on a new line.

#### Explanation

A series of lucky numbers looks like: **1**, **2**, **4**, **8**, **11**, **12**, **14**, **18**, **21**, **22**, **24**, **28**, **41**, **42**, **44**, **48**, ... .

4 1 7 2 18 2 25 2 0

14 21 28 1