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 (1≤n≤1031≤n≤103) — the number of tasks in Petya's homework. The next nn lines contain two integers kiki​ (1≤ki≤10121≤ki​≤1012) and xixi​ (1≤xi≤91≤xi​≤9) — ii-th Petya's task in which you need to find a kiki​-th positive number, the digital root of which is xixi​.

Output

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

Examples

Inputcopy Outputcopy
3
1 5
5 2
3 1
5
38
19

今天在数学课上,佩佳学习了数字根。数字根是一个非负整数的单数字值,通过迭代求和的过程获得,在每次迭代中使用上一次迭代的结果来计算数字和。过程一直持续到得到一个一位数为止。我们用S(x)来表示x的数字根。于是S(5)=5,S(38)=S(3+8=11)=S(1+1=2)=2,S(10)=S(1+0=1)=1。佩佳的家庭作业有n个任务:找到数字根为x的第k个正整数。佩佳已经解决了所有的问题,但他不知道是否正确。你的任务是解决佩佳家庭作业中的所有n个问题。

#include<iostream>
#define  int long long
#define N 1000005
#define INF 0x3f3f3f3f
using namespace std;
signed main()
 {
ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
    int x,y;
    cin>>x>>y;
    if(x==1) cout<<y<<endl;
    else cout<<(x-1)*9+y<<endl;
}
    return 0; 
 }

Logo

集算法之大成!助力oier实现梦想!

更多推荐