lottery

Time limit: 0.5s Memory limit: 64MB Input: Output:

Task

Tommaso would like to buy a new computer but unfortunately he doesn't have enough money. So he decided to try his luck and buy some lottery tickets.

The lottery tickets are numbered, and one of his friends told him the secret to win the lottery: in a winning ticket the sum of the digits of the ticket number is exactly NN and the ticket number does not contain 33 consecutive equal digits.

When Tommaso arrived to the lottery shop, he saw that some tickets were already sold. The current ticket number is SS and Tommaso must buy the tickets in order (first ticket number SS, then ticket number S+1S+1, then ticket number S+2S+2, and so on).

He wants to buy some tickets until he finds a winning one. Note that it is possible that Tommaso is not able to buy a winning ticket.

What is the number of the winning ticket bought by Tommaso?

Help Tommaso to find the answer in TT different scenarios.

Input

The first line contains a single integer TT (1T2001 \le T \le 200), denoting the number of test cases.

The following TT lines contains 22 integers: NN and SS (1N80 0001 \le N \le 80 \ 000), (1S10 0001 \le |S| \le 10 \ 000).

For tests worth 3030 points, N32N \le 32 and the length of each SS does not exceed 44.

For tests worth 3030 more points, N2 000N \le 2 \ 000 and the length of each SS does not exceed 300300.

Output

You need to write TT lines with an integer: the number of the winning ticket bought by Tommaso, or 1-1 if he can not buy one.

Example 1

stdin

4
7 502
1 123
10 99
16 4440

stdout

502
-1
109
4453

Explanation

In the first sample case:

In the first test Tommaso can buy the first ticket since it is a winning ticket.

In the second test case Tommaso can not buy any winning ticket. Note that the ticket number 10001000 is not a winning ticket since it contains three consecutive 00.

Log in or sign up to be able to send submissions!