CF1107B.Digital root

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Digital root

Today at the lesson of mathematics, Petya learns about the digital root.

The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.

Let's denote the digital root of xx as S(x)S(x). Then S(5)=5S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1S(10)=S(1+0=1)=1.

As a homework Petya got nn tasks of the form: find kk-th positive number whose digital root is xx.

Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all nn tasks from Petya's homework.

Input

The first line contains a single integer nn (1n1031 \le n \le 10^3) — the number of tasks in Petya's homework. The next nn lines contain two integers kik_i (1ki10121 \le k_i \le 10^{12}) and xix_i (1xi91 \le x_i \le 9) — ii-th Petya's task in which you need to find a kik_i-th positive number, the digital root of which is xix_i.

Output

Output nn lines, ii-th line should contain a single integer — the answer to the ii-th problem.

Samples

3
1 5
5 2
3 1
5
38
19

在线编程 IDE

建议全屏模式获得最佳体验