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 $x$ as $S(x)$. Then $S(5)=5$, $S(38)=S(3+8=11)=S(1+1=2)=2$, $S(10)=S(1+0=1)=1$.

As a homework Petya got $n$ tasks of the form: find $k$-th positive number whose digital root is $x$.

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


-----Input-----

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


-----Output-----

Output $n$ lines, $i$-th line should contain a single integer — the answer to the $i$-th problem.


-----Example-----
Input
3
1 5
5 2
3 1

Output
5
38
19

Source: codeforces | Difficulty: EASY
Tags: Number theory

Mathematics


Solutions:
t = int(input())
while t != 0:
	(x, y) = map(int, input().split())
	print((x - 1) * 9 + y)
	t -= 1


n = int(input())
for _ in range(n):
	(k, x) = map(int, input().split(' '))
	print((k - 1) * 9 + x)


q = int(input())
for i in range(q):
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	print((n - 1) * 9 + m)


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
for n in range(ii()):
	(k, x) = mi()
	ans = 9 * (k - 1) + x
	print(ans)


R = lambda : map(int, input().split())
for tst in range(int(input())):
	(x, y) = R()
	print(9 * (x - 1) + y)


t = int(input())
a = []
for i in range(t):
	b = list(map(int, input().split()))
	a.append(b)
for i in range(t):
	print(9 * a[i][0] - (9 - a[i][1]))


n = int(input())
for i in range(0, n):
	(k, x) = input().split()
	k = int(k)
	x = int(x)
	print(f'{x + (k - 1) * 9}')


t = int(input())
while t != 0:
	(k, x) = map(int, input().split())
	val = x + 9 * (k - 1)
	print(val)
	t = t - 1


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
q = ii()
while q > 0:
	(k, x) = tuple(mi())
	print((k - 1) * 9 + x)
	q = q - 1


for i in range(int(input())):
	(k, l) = map(int, input().split())
	print((k - 1) * 9 + l)


n = int(input())
for i in range(n):
	(k, x) = map(int, input().split())
	print('%d' % ((k - 1) * 9 + x))


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	print((a - 1) * 9 + b)


from collections import defaultdict, deque

def dig_root(x):
	x = str(x)
	if len(x) == 1:
		return x
	else:
		return dig_root(sum((int(c) for c in x)))
for _ in range(int(input())):
	(k, d) = map(int, input().split())
	print(d + (k - 1) * 9)


t = int(input())
while t > 0:
	kx = list(map(int, input().split()))
	k = kx[0]
	x = kx[1]
	print((k - 1) * 9 + x)
	t -= 1


t = int(input())
while t:
	t -= 1
	[x, y] = [int(i) for i in input().split()]
	print((x - 1) * 9 + y)


T = int(input())
for _ in range(T):
	(k, x) = [int(x) for x in input().split()]
	print((k - 1) * 9 + x)


n = int(input())
m = []
N = 2
for i in range(n):
	row = input().split()
	for j in range(len(row)):
		row[j] = int(row[j])
	m.append(row)
for i in range(n):
	sum = (m[i][0] - 1) * 9 + m[i][1]
	print(sum)


from math import *
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	base = x
	x += 9 * (k - 1)
	print(x)


import copy
import fractions
import itertools
import string
import sys

def powmod(x, p, m):
	if p <= 0:
		return 1
	if p <= 1:
		return x % m
	return powmod(x * x % m, p // 2, m) * (x % m) ** (p % 2) % m

def to_basex(num, x):
	while num > 0:
		yield (num % x)
		num //= x

def from_basex(it, x):
	ret = 0
	p = 1
	for d in it:
		ret += d * p
		p *= x
	return ret

def core():
	n = int(input())
	for _ in range(n):
		(k, x) = [int(x) for x in input().split()]
		ans = x + (k - 1) * 9
		print(ans)
core()


for t in range(int(input())):
	(n, m) = map(int, input().split())
	print(m + (n - 1) * 9)


def main():
	n = int(input())
	for i in range(n):
		tmp = input()
		tmp = tmp.split(' ')
		(k, x) = tmp
		(k, x) = (int(k), int(x))
		print((k - 1) * 9 + x)
main()


for _ in [0] * int(input()):
	(k, x) = map(int, input().split())
	print(9 * (k - 1) + x)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	print((a - 1) * 9 + b)


q = int(input())
while q > 0:
	q -= 1
	(k, x) = tuple(map(int, input().split()))
	print((k - 1) * 9 + x)


from sys import stdin
from math import gcd
input = stdin.buffer.readline
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)


q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	if a == 1:
		print(b)
	else:
		print(9 * (a - 1) + b)


import sys, math, string, bisect
input = sys.stdin.readline
from collections import deque
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	print(9 * (a - 1) + b)


t = int(input())
for cases in range(0, t):
	(x, n) = map(int, input().split())
	print(n + (x - 1) * 9)


from sys import stdin, stdout
q = int(stdin.readline())
for i in range(q):
	(k, x) = map(int, stdin.readline().split())
	stdout.write(str((k - 1) * 9 + x) + '\n')


n = int(input())
for i in range(n):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	print((x - 1) * 9 + y)


s1 = int(input())
for i in range(s1):
	(s2, s3) = input().split()
	s2 = int(s2)
	s3 = int(s3)
	print((s2 - 1) * 9 + s3)


t = int(input())
for i in range(t):
	(k, x) = list(map(int, input().strip().split()))
	print((k - 1) * 9 + x)


n = int(input())
for i in range(n):
	(q, l) = map(int, input().split())
	print(9 * (q - 1) + l)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(k, x) = mp()
	print(x + (k - 1) * 9)


t = int(input())
for _ in range(t):
	(k, x) = list(map(int, input().split()))
	print(x + (k - 1) * 9)


q = int(input())
i = 0
while i < q:
	i = i + 1
	(k, x) = input().split()
	k = int(k)
	x = int(x)
	a = x + 9 * (k - 1)
	print(a)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	res = 0
	res += 9 * (n - 1) + m
	print(res)


import sys
stdin = sys.stdin
n = int(stdin.readline())
for _ in range(n):
	arr = stdin.readline().split()
	arr = [int(x) for x in arr]
	k = arr[0]
	root = arr[1]
	out = k * 9 + (root - 9)
	print(out)


n = int(input())
for x in range(n):
	(p, k) = list(map(int, input().split()))
	jam = (p - 1) * 9
	print(jam + k)


import sys
n = int(sys.stdin.readline())
for i in range(n):
	(k, x) = map(int, sys.stdin.readline().split())
	print(x + (k - 1) * 9)


ks = []
xs = []
num = int(input())
for i in range(0, num):
	t = input()
	(n, w) = map(int, t.split())
	ks.append(n)
	xs.append(w)
for i in range(0, len(ks)):
	x = xs[i]
	k = ks[i]
	print(x + (k - 1) * 9)


q = int(input())
for _ in range(q):
	(k, x) = map(int, input().strip().split())
	print((k - 1) * 9 + x)


n = int(input())
for _ in range(n):
	s = input().split()
	k = int(s[0])
	x = int(s[1])
	print(9 * (k - 1) + x)


import sys
data = sys.stdin.read().splitlines()
n = int(data[0])
for line in data[1:]:
	(n, x) = map(int, line.split())
	print((n - 1) * 9 + x)


sub = [0, 8, 7, 6, 5, 4, 3, 2, 1]
N = int(input())
for i in range(0, N):
	(K, X) = map(int, input().split())
	print(K * 9 - sub[X % 9])


n = int(input())
for i in range(n):
	(m, sum) = map(int, input().split())
	print(9 * (m - 1) + sum)


def solve(k, x):
	return x + (k - 1) * 9
for _ in range(int(input())):
	print(solve(*list(map(int, input().split()))))


n = int(input())
ans = list()
for j in range(n):
	s = input().split()
	k = int(s[0])
	x = int(s[1])
	if x == 9:
		ans.append(9 * k)
	else:
		ans.append(9 * (k - 1) + x)
for j in range(n):
	print(ans[j])


n = int(input())
for i in range(n):
	ls = input().split()
	a = int(ls[0])
	b = int(ls[1])
	print(b + (a - 1) * 9)


def gen(x, i):
	if x >= i:
		return x - i
	return 10 - i + x
for _ in range(int(input())):
	(k, x) = map(int, input().split())
	if k == 1:
		print(x)
		continue
	l_list = [gen(x, i) for i in range(10)]
	l = l_list[k % 10 - 1]
	if k <= x + 1:
		ans = str(k - 1) + str(l)
		print(int(ans))
		continue
	base = int(str(x) + '0')
	z = x + 1
	rem = (k - z) * 9
	print(base + rem)


for i in range(int(input())):
	X = list(map(int, input().split()))
	print((X[0] - 1) * 9 + X[1])


t = int(input())
for a0 in range(t):
	(k, x) = map(int, input().split())
	if k == 1:
		print(x)
	else:
		x += 9 * (k - 1)
		print(x)


a = int(input())
for i in range(a):
	(b, c) = input().split()
	b = int(b)
	c = int(c)
	print(b * 9 - 9 + c)


i = int(input())
k = 0
while k < i:
	p = input()
	p = list(map(int, p.split(' ')))
	store = p[1] + 9 * (p[0] - 1)
	print(store)
	k = k + 1


def digitalroot(k, x):
	return 9 * (k - 1) + x
n = int(input())
for _ in range(n):
	(k, x) = map(int, input().split())
	print(digitalroot(k, x))


T = int(input())
while T:
	(k, x) = map(int, input().split())
	print(9 * (k - 1) + x)
	T -= 1


import math as m

def dig_root(n):
	nod = m.floor(m.log10(n) + 1)
	if nod != 1:
		nodt = str(nod)
		sum1 = sum(nodt)
		k = dig_root(sum1)
		return k
	else:
		return n
n = int(input())
temp = []
for i in range(n):
	(a, b) = list(map(int, input().split(' ')))
	temp.append([a, b])
sol = []
for i in range(n):
	a = temp[i][0]
	b = temp[i][1]
	sol.append(b + 9 * (a - 1))
for i in range(n):
	print(sol[i])


for itr in range(int(input())):
	linea = [int(x) for x in input().split()]
	print(linea[1] + (linea[0] - 1) * 9)


nb_test = int(input())
for _ in range(nb_test):
	(a, b) = [int(x) for x in input().split()]
	print(9 * (a - 1) + b)


n = int(input())
for i in range(0, n):
	a = list(map(int, input().split()))
	b = (a[0] - 1) * 9 + a[1]
	print(b)


list_int_input = lambda inp: list(map(int, inp.split()))
int_input = lambda inp: int(inp)
string_to_list_input = lambda inp: list(inp)
n = int_input(input())
while n > 0:
	n -= 1
	kx = list_int_input(input())
	print(kx[1] + 9 * (kx[0] - 1))


n = int(input())
t = 0
lis = []
for i in range(n):
	m = list(map(int, input().split()))
	print(m[1] + 9 * (m[0] - 1))


t = int(input())
while t:
	(k, n) = map(int, input().split())
	print(9 * (k - 1) + n)
	t -= 1


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().split())
	if n == 1:
		print(m)
	else:
		s = 9 * (n - 1) + m
		print(s)


n = int(input())
for i in range(n):
	(k, r) = map(int, input().split())
	print(r + (k - 1) * 9)


n = int(input())
for _ in range(n):
	(k, x) = map(int, input().split())
	if k == 1:
		print(x)
	else:
		print(x + (k - 1) % 1000000000007 * 9)


n = int(input())
for t in range(n):
	(k, x) = [int(i) for i in input().split()]
	print(x + 9 * k - 9)


t = int(input())
for i in range(t):
	li = [int(x) for x in input().split()]
	print(li[1] + (li[0] - 1) * 9)


from sys import stdin

def readLine():
	return stdin.readline().strip()

def readInt():
	return int(readLine())

def readInts():
	return list(map(int, readLine().split()))
f = lambda k, x: 9 * k - 9 + x

def main():
	N = readInt()
	for i in range(N):
		(K, X) = readInts()
		print(f(K, X))
main()


t = int(input())
for q in range(t):
	(k, n) = map(int, input().strip().split())
	print(n + 9 * (k - 1))


n = int(input())
k = []
x = []
for i in range(n):
	(a, b) = map(int, input().split())
	k.append(a)
	x.append(b)
l = []
for i in range(n):
	l.append((k[i] - 1) * 9 + x[i])
for i in l:
	print(i)


n = int(input())
while n:
	n -= 1
	(k, x) = map(int, input().split())
	ans = 9 * (k - 1) + x
	print(ans)


n = int(input())
for i in range(n):
	l = list(map(int, input().split()))
	k = l[0]
	x = l[1]
	r = x + (k - 1) * 9
	print(r)


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input():
	return sys.stdin.readline().strip()

def ceil(a, b=1):
	return int(-(-a // b))

def round(x):
	return int((x * 2 + 1) // 2)

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
for i in range(N):
	(k, x) = MAP()
	print(k * 9 - (9 - x))


def S(x):
	string = str(x)
	len_str = len(string)
	summa = 0
	for i in range(len_str):
		summa += int(string[i])
	if summa > 9:
		return S(summa)
	else:
		return summa
n = int(input())
for i in range(n):
	(k, x) = map(int, input().split())
	print(x + (k - 1) * 9)


for u in range(int(input())):
	(k, s) = map(int, input().split())
	print(9 * (k - 1) + s)


n = int(input())
k = []
s = []
for i in range(n):
	S = list(map(int, input().split()))
	k.append(S[0])
	s.append(S[1])
for i in range(n):
	print(s[i] + (k[i] - 1) * 9)


NumOfInputs = int(input())
while NumOfInputs > 0:
	(K, X) = (int(k) for k in input().split(' '))
	print((K - 1) * 9 + X)
	NumOfInputs -= 1


t = int(input())
i = 0
while t > 0:
	t = t - 1
	(n, k) = map(int, input().split())
	print((n - 1) * 9 + k)


n = int(input())
for i in range(n):
	(k, x) = map(int, input().split())
	if k == 1:
		print(x)
	else:
		print(x + 9 * k - 9)


q = int(input())
for _ in range(q):
	(k, x) = [int(x) for x in input().split()]
	if x == 0:
		print(0)
		continue
	res = 9 * (k - 1) + x
	print(res)


q = int(input())
for i in range(q):
	pair = input().split(' ')
	x = int(pair[0])
	y = int(pair[1])
	print(y + (x - 1) * 9)


from collections import deque
from sys import stdin
lines = deque((line.strip() for line in stdin.readlines()))

def nextline():
	return lines.popleft()

def types(cast, sep=None):
	return tuple((cast(x) for x in strs(sep=sep)))

def ints(sep=None):
	return types(int, sep=sep)

def strs(sep=None):
	return tuple(nextline()) if sep == '' else tuple(nextline().split(sep=sep))

def main():
	T = int(nextline())
	for testCase in range(1, T + 1):
		(k, x) = ints()
		print(9 * k + x - 9)
main()


import sys
n = int(sys.stdin.readline().strip())
for i in range(0, n):
	line = sys.stdin.readline().strip().split()
	k = int(line[0])
	x = int(line[1])
	print((k - 1) * 9 + x)


q = int(input())
KX = [list(map(int, input().split())) for i in range(q)]
for (k, x) in KX:
	print(x + (k - 1) * 9)

def digitsum(x):
	ANS = 0
	for i in str(x):
		ANS += int(i)
	return ANS

def digitroot(x):
	while x >= 10:
		x = digitsum(x)
	return x


R = lambda : map(int, input().split())
for tst in range(int(input())):
	x = list(R())
	print(9 * (x[0] - 1) + x[1])


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
sys.setrecursionlimit(200000)
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(n, a) = num_input()
	print((n - 1) * 9 + a)
t = 1
t = int(input())
for _ in range(t):
	solve()


import sys
from math import *
from copy import copy
from collections import deque
n = int(input())
for i in range(n):
	(k, x) = input().split()
	(k, x) = (int(k), int(x))
	print(x + (k - 1) * 9)


def main():
	n = int(input())
	arr = []
	for i in range(0, n):
		(x2, y2) = [int(float(x)) for x in input().split(' ')]
		arr.append([x2, y2])
	for i in range(0, n):
		tupla = arr[i]
		kesimo = tupla[0]
		valor = tupla[1]
		print((kesimo - 1) * 9 + valor)
main()


import math
import sys

def main():
	n = int(input())
	for i in range(n):
		(k, x) = [int(x) for x in input().split(' ')]
		print(x + 9 * (k - 1))
main()


for t in range(int(input())):
	(lambda k, n: print(9 * (k - 1) + n))(*map(int, input().split()))


t = int(input())
while t > 0:
	a = input()
	a = a.split(' ')
	a[0] = int(a[0])
	a[1] = int(a[1])
	print(a[1] + 9 * (a[0] - 1))
	t -= 1


n = int(input())
for i in range(n):
	(k, a) = map(int, input().split())
	num = (k - 1) * 9
	num = num + a
	print(str(num))


def droot(i):
	sum = 0
	while True:
		while i:
			r = i % 10
			sum += r
			i = i // 10
		if sum <= 9:
			return sum
q = int(input())
for _ in range(q):
	(k, x) = map(int, input().split())
	i = 0
	while droot(i) != x:
		i += 1
	i += 9 * (k - 1)
	print(i)


m = int(input())
for i in range(m):
	(k, x) = map(int, input().split())
	res = (k - 1) * 9 + x
	print(res)


n = int(input())
for _ in range(n):
	kx = list(map(int, input().split()))
	(k, x) = (kx[0], kx[1])
	if x == 9:
		print(9 * k)
	else:
		print(9 * (k - 1) + x)


q = int(input())
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for x in range(q):
	(k, m) = list(map(int, input().split()))
	print(m + 9 * (k - 1))


from itertools import combinations
from sys import stdin, stdout

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline()
N = intIn()
for i in range(N):
	a = listIn()
	print((a[0] - 1) * 9 + a[1])


queries = int(input())
for x in range(0, queries):
	fuck = str(input()).split()
	x = int(fuck[0])
	y = int(fuck[1])
	print(y + 9 * (x - 1))


def main():
	n = int(input())
	for _ in range(n):
		(k, x) = map(int, input().split())
		if x != 9:
			print((k - 1) * 9 + x)
		else:
			print(k * 9)
main()


q = int(input())
while q:
	(k, x) = input().split(' ')
	k = int(k)
	x = int(x)
	print(x + (k - 1) * 9)
	q -= 1


n = int(input())

def s(n):
	if 1 <= n <= 9:
		return n
	else:
		return s(sum(map(int, str(n))))
for _ in range(n):
	(k, x) = map(int, input().split())
	ans = 9 * k
	while s(ans) != x:
		ans -= 1
	print(ans)


n = int(input())
for I in range(n):
	(k, x) = [int(i) for i in input().split()]
	print(x + (k - 1) * 9)


t = int(input())
for z in range(t):
	(k, x) = [int(x) for x in input().split()]
	for i in range(x + 1, x + 10):
		p = i % 9
		if p == 0:
			p = 9
		if p == x:
			diff = i - x
			break
	ans = x + (k - 1) * diff
	print(ans)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	(k, x) = map(int, sys.stdin.readline().split(' '))
	if x % 9:
		print(9 * (k - 1) + x % 9)
	else:
		print(9 * k)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for i in range(int(input())):
	(x, d) = map(int, input().split())
	print(9 * x - 9 + d)


n = int(input())
while n > 0:
	p = 0
	(k, x) = [int(i) for i in input().split()]
	if k == 1:
		print(x)
	else:
		print(x + (k - 1) * 9)
	n -= 1


import sys
n = int(input())
for i in range(0, n):
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)


q = int(input())
o = 0
v = 0
k = 0
x = 0
while o < q:
	(k, x) = map(int, input().split())
	print(x + (k - 1) * 9)
	o += 1


for c in range(int(input())):
	(k, d) = map(int, input().split())
	print((k - 1) * 9 + d)


def main():
	requests = int(input())
	for i in range(requests):
		(k, x) = map(int, input().split())
		print(x + 9 * (k - 1))
main()


from sys import stdin
read = stdin.readline
n = int(read())
for _t in range(n):
	(k, x) = map(int, read().split())
	print(9 * (k - 1) + x)


n = int(input())
l1 = []
for i in range(n):
	(k, x) = map(int, input().split())
	l1.append(x + 9 * (k - 1))
for item in l1:
	print(item)


n = int(input())
for i in range(n):
	(a1, a2) = map(int, input().split())
	print(9 * (a1 - 1) + a2)


def program():
	(k, x) = map(int, input().split())
	print(9 * (k - 1) + x)
for i in range(int(input())):
	program()


f = 4

def output(k, x):
	k = int(k)
	x = int(x)
	return x + (k - 1) * 9
no = input()
for i in range(int(no)):
	in1 = input()
	l = in1.split(' ')
	print(output(l[0], l[1]))


n = int(input())
while n > 0:
	(k, x) = map(int, input().split())
	print(x + (k - 1) * 9)
	n -= 1


n = int(input())
for i in range(n):
	l = [int(x) for x in input().split()]
	su = l[1]
	print(su + (l[0] - 1) * 9)


from math import *
from itertools import *
from collections import *
from functools import reduce
Q = q = quit
inf = float('inf')

def input_ints():
	return list(map(int, input().split()))

def input_floats():
	return list(map(float, input().split()))

def input_strings():
	return input().split()
n = int(input())
k = []
x = []
for i in range(n):
	(k_i, x_i) = input_ints()
	k.append(k_i)
	x.append(x_i)
for i in range(n):
	print(x[i] + 9 * (k[i] - 1))


from sys import stdin, stdout
import math
q = int(input())
while q > 0:
	(k, x) = map(int, input().split())
	ans = 9 * (k - 1) + x
	print(ans)
	q = q - 1


numOfTasks = int(input())
while numOfTasks != 0:
	numOfTasks -= 1
	(k, digitalRoot) = map(int, input().split(' '))
	print(digitalRoot + (k - 1) * 9)


n = int(input())
ans = ''
for i in range(n):
	s = input()
	(k, x) = s.split(' ')
	k = int(k)
	x = int(x)
	if k == 1:
		rez = x
	else:
		rez = x + (k - 1) * 9
	ans += '{}\n'.format(rez)
print(ans)


def kth_d_root(k, x):
	return 9 * (k - 1) + x

class CodeforcesTask1107BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.queries = []

	def read_input(self):
		self.n = int(input())
		for x in range(self.n):
			self.queries.append([int(y) for y in input().split(' ')])

	def process_task(self):
		for query in self.queries:
			self.result += '{0}\n'.format(kth_d_root(*query))

	def get_result(self):
		return self.result
Solution = CodeforcesTask1107BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n4 = input().split()
n = int(n4[0])
i = n
while i > 0:
	n2 = input().split()
	n3 = int(n2[1]) + 9 * (int(n2[0]) - 1)
	print(n3)
	i = i - 1


n = int(input())
for i in range(n):
	num = input()
	num = num.split(' ')
	res = (int(num[0]) - 1) * 9 + int(num[1])
	print(res)


n = int(input())
for item in range(n):
	(k, a) = [int(x) for x in input().split()]
	print(a + 9 * (k - 1))


from sys import stdin, stdout
input = stdin.readline
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	(k, x) = mapin()
	print(x + (k - 1) * 9)


for _ in range(int(input())):
	(k, a) = map(int, input().split())
	print(9 * (k - 1) + a)


from math import *
t = int(input())
for _ in range(t):
	(k, n) = map(int, input().split(' '))
	print(n + (k - 1) * 9)


n = int(input())
for x in range(n):
	(a, b) = map(int, input().split())
	print(b + 9 * (a - 1))


import sys

def print_root(k, x):
	print(str(9 * (k - 1) + x))

def process_input():
	num_process = int(sys.stdin.readline())
	for i in range(num_process):
		entry = str(sys.stdin.readline()).split()
		print_root(int(entry[0]), int(entry[1]))
process_input()


def s(n):
	while n >= 10:
		k = 0
		while n > 0:
			k += n % 10
			n = n // 10
		n = k
	return n
n = int(input())
for _ in range(n):
	(k, x) = map(int, input().split())
	print(x + 9 * (k - 1))


mem = dict()

def droot(n):
	if n not in mem:
		if n < 10:
			mem[n] = n
		else:
			mem[n] = droot(sum([int(el) for el in str(n)]))
	return mem[n]
n = int(input())
for i in range(n):
	(k, x) = map(int, input().split())
	print(x + (k - 1) * 9)


for step in range(int(input())):
	(k, x) = map(int, input().split())
	print(x + 9 * (k - 1))


import math
import sys
import bisect
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(k, x) = map(int, input().split())
	print(x + 9 * (k - 1))


n = int(input())
answer = []
while n:
	[k, x] = list(map(int, input().split()))
	answer.append(x + (k - 1) * 9)
	n -= 1
for ans in answer:
	print(ans)


for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print(y + (x - 1) * 9)


n = int(input())
ans = []
for i in range(n):
	(k, x) = map(int, input().split())
	a = x + 9 * (k - 1)
	ans.append(a)
for elem in ans:
	print(elem)


n = int(input())
for _ in range(n):
	(o, t) = list(map(int, input().split()))
	print(9 * (o - 1) + t)


n = int(input())
for j in range(n):
	inp = input().split()
	k = int(inp[0])
	x = int(inp[1])
	print(9 * (k - 1) + x)


import sys
R = lambda : map(int, input().split())
t = int(input())
while t:
	(k, x) = R()
	print(x + (k - 1) * 9)
	t -= 1


def f(a, b):
	return b + (a - 1) * 9
for _ in range(int(input())):
	(a, b) = map(int, input().strip().split())
	print(f(a, b))


t = int(input())
lst = []
res = []
for i in range(0, t):
	lst = [int(i) for i in input().split()]
	ele = 9 * lst[0] + lst[1] - 9
	res.append(ele)
for i in range(0, t):
	print(res[i])


def get():
	return map(int, input().split())
n = int(input())
for i in range(n):
	(a, b) = get()
	print(9 * (a - 1) + b)


cases = int(input())
while cases > 0:
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)
	cases -= 1


a = input()
a = int(a)
for i in range(0, a):
	(c, d) = input().split(' ')
	c = int(c)
	d = int(d)
	print(9 * (c - 1) + d)


def FindDigitalRoot(n):
	if n == n % 10:
		return n
	temp_n = n
	sum = 0
	while temp_n != 0:
		sum += temp_n % 10
		temp_n = temp_n / 10
	return FindDigitalRoot(sum)

def FindKthDigitalRoot(k, x):
	n = 0
	for i in range(1, 10):
		if FindDigitalRoot(i) == x:
			n = i
			break
	n += (k - 1) * 9
	return n
tasks = int(input())
result_val = []
for _ in range(tasks):
	(k, x) = map(int, input().split())
	result_val.append(FindKthDigitalRoot(k, x))
for i in range(tasks):
	print(result_val[i])


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque, Counter, OrderedDict
import threading
from heapq import *

def main():
	for _ in range(int(input())):
		(k, x) = map(int, input().split())
		print((k - 1) * 9 + x)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
arr = []
for i in range(n):
	(k, x) = input().split(' ')
	arr.append([int(k), int(x)])
for i in arr:
	num_trial = int(i[0])
	root = int(i[1])
	print(root + 9 * (num_trial - 1))


n = int(input())
lst = list()
for i in range(n):
	a = input().split()
	lst.append(a)
for i in range(n):
	k = int(lst[i][0])
	x = int(lst[i][1])
	print(x + (k - 1) * 9)


def rev(i, x):
	return (i - 1) * 9 + x
q = int(input())
for _ in range(q):
	(i, x) = input().split()
	i = int(i)
	x = int(x)
	print(rev(i, x))


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def main():
	arr = [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9]
	for tc in range(int(input())):
		(k, x) = get_ints()
		print(arr[x] + 9 * (k - 1))
main()


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(k + (n - 1) * 9)


def binNumber(n, size):
	return bin(n)[2:].zfill(size)

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
n = int(input())
for _ in range(n):
	(k, x) = map(int, input().split())
	print(x + (k - 1) * 9)


r = [int(x) for x in input().split()]
n = r[0]
for i in range(n):
	s = [int(x) for x in input().split()]
	k = s[0]
	x = s[1]
	print(x + (k - 1) * 9)


n = int(input())
while n:
	(x, y) = map(int, input().split())
	print((x - 1) * 9 + y)
	n -= 1


gi = lambda : list(map(int, input().split()))
for k in range(gi()[0]):
	(n, x) = gi()
	print((n - 1) * 9 + x)


def root(s):
	str_int = str(s)
	while len(str_int) > 1:
		str_int = str(sum(map(int, str_int)))
	return str_int
n = int(input())
for i in range(n):
	k_x = list(map(int, input().rstrip().split()))
	(k, x) = (k_x[0], k_x[1])
	print(x + 9 * (k - 1))


def dr(n):
	sum = 0
	while n > 0:
		while n > 0:
			sum += n % 10
			n = n // 10
		if sum > 9:
			n = sum
			sum = 0
		else:
			break
	return sum
n = int(input())
for i in range(n):
	t = list(map(int, input().split()))
	k = t[0]
	x = t[1]
	if k == 1:
		print(x)
	else:
		print(x + (k - 1) * 9)


def main_function():
	input_data = [[int(i) for i in input().split(' ')] for k in range(int(input()))]
	for i in input_data:
		(k, x) = i
		print(9 * (k - 1) + x)
main_function()


import sys
tc = int(sys.stdin.readline())
for _ in range(tc):
	(k, n) = map(int, sys.stdin.readline().split())
	print(9 * k - (9 - n))


t = int(input())
while t:
	arr = [int(x) for x in input().split()]
	k = arr[0]
	x = arr[1]
	ans = x + (k - 1) * 9
	print(ans)
	t -= 1


INF = 100000000
from collections import deque
t = int(input())
for test in range(t):
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)


n = int(input())
for ii in range(n):
	(k, x) = [int(xx) for xx in input().split(' ')]
	print((k - 1) * 9 + x)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(t,) = I()
while t:
	t -= 1
	(k, x) = I()
	m = 9 * (k - 1) + x
	print(m)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	(k, x) = map(int, input().split())
	r = 9 * (k - 1) + x
	print(r)


q = int(input())
while q:
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if k != 0:
		print((n - 1) * 9 + k)
	else:
		print(0)
	q -= 1


def solve(k, n):
	return n + (k - 1) * 9
t = 1
t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	print(solve(n, k))
	t -= 1


for i in range(int(input())):
	(k, n) = [int(j) for j in input().split()]
	print(n + (k - 1) * 9)


__author__ = 'Esfandiar'
res = [0, 19, 38, 57, 76, 95, 24, 16, 17, 18]
for i in range(int(input())):
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)


n = int(input())
while n:
	n -= 1
	(k, x) = list(map(int, input().split()))
	print((k - 1) * 9 + x)


def sod(n):
	sum = 0
	while n:
		sum += n % 10
		n //= 10
		if n == 0 and sum >= 10:
			n = sum
			sum = 0
	return sum
n = int(input())
for t in range(n):
	(k, x) = map(int, input().split())
	i = (k - 1) * 9
	while 1:
		i += 1
		if sod(i) == x:
			print(i)
			break


n = int(input())
for i in range(n):
	(k, root) = map(int, input().split())
	res = 9 * (k - 1) + root
	print(res)


def f(l):
	(k, x) = l
	return 9 * (k - 1) + x
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print(f(l))


import re, math, decimal, bisect, collections

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
for i in range(iread()):
	(k, x) = viread()
	print(9 * (k - 1) + x)


def root(lst):
	a = list()
	for elem in lst:
		a.append(9 * (elem[0] - 1) + elem[1])
	return a
n = int(input())
b = list()
for i in range(n):
	(k, x) = [int(j) for j in input().split()]
	b.append([k, x])
print(*root(b))


n = int(input())
pairs = []
for i in range(n):
	pairs.append([int(x) for x in input().split(' ')])
for (k, x) in pairs:
	if k == 1:
		print(x)
	else:
		print(9 * (k - 1) + x)


t = int(input())
for i in range(0, t):
	(k, x) = map(int, input().split())
	print(x + 9 * (k - 1))


for _ in range(int(input())):
	(kth, root) = map(int, input().split())
	print(root + (kth - 1) * 9)


import sys
from atexit import register
from io import FileIO, StringIO
sys.stdin = StringIO(FileIO(0).read().decode())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	n = int(input())
	for i in range(n):
		(k, x) = map(int, input().split())
		print(9 * (k - 1) + x)
main()


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def binsearch(arr, b, low, high):
	if low == high:
		return low
	if arr[math.ceil((low + high) / 2)] < b:
		return binsearch(arr, b, low, math.ceil((low + high) / 2) - 1)
	else:
		return binsearch(arr, b, math.ceil((low + high) / 2), high)

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s

def calc(n, m, r):
	s = 0
	for i in range(0, r + 1, 2):
		s += ncr1(n, i) * ncr1(m, i)
		s %= mod
	return s

def modu(a, n):
	if a % n == 0:
		return n
	return a % n
for i in range(int(input())):
	(k, n) = map(int, input().split())
	print(n + 9 * (k - 1))


n = int(input())

def go(k, x):
	return x + (k - 1) * 9
for _ in range(n):
	(k, x) = list(map(int, input().split()))
	print(go(k, x))


def dr(number):
	while number > 9:
		nn = 0
		for i in range(len(str(number))):
			nn += int(str(number)[i])
		number = nn
	return number
n = int(input())
for i in range(n):
	(k, x) = list(map(int, input().split()))
	print((k - 1) * 9 + x)


t = int(input(''))
for i in range(t):
	(ki, xi) = map(int, input('').split())
	ans = xi + 9 * (ki - 1)
	print(ans)


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True
factorial_modP = []

def warm_up_fac(MOD):
	global factorial_modP, fac_warmup
	if fac_warmup:
		return
	factorial_modP = [1 for _ in range(fac_warmup_size + 1)]
	for i in range(2, fac_warmup_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warmup = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	global fac_warmup, factorial_modP
	if not fac_warmup:
		warm_up_fac(MOD)
		fac_warmup = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = True
testingMode = False
fac_warmup_size = 10 ** 5 + 100
optimiseForReccursion = True

def main():
	(n, k) = get_tuple()
	n -= 1
	print(k + n * 9)
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if testingMode else main()
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


n = int(input())
for i in range(n):
	(k, x) = [int(c) for c in input().split()]
	ans = x + (k - 1) * 9
	print(ans)


from sys import stdin
dp = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
n = int(stdin.readline().strip())
for _ in range(n):
	(k, x) = list(map(int, stdin.readline().split()))
	print((k - 1) * 9 + dp[x])


amount = int(input())
for i in range(amount):
	(k, x) = [int(s) for s in input().split()]
	print(9 * (k - 1) + x)


t = int(input())
for i in range(0, t):
	kx = list(map(int, input().strip().split()))
	k = kx[0]
	x = kx[1]
	if k == 1:
		print(x)
	else:
		print(x + 9 * (k - 1))


def FindNumber(position, root):
	return root + 9 * (position - 1)
casos = int(input())
SolucionFinal = []
for i in range(casos):
	data = input().split(' ')
	Solucion = FindNumber(int(data[0]), int(data[1]))
	SolucionFinal.append(Solucion)
for k in range(len(SolucionFinal)):
	print(SolucionFinal[k])


n = int(input())
while n > 0:
	(a, b) = map(int, input().split())
	print(b + 9 * (a - 1))
	n -= 1


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	try:
		f = open('input' + str(inId) + '.txt', 'r')
		sys.stdin = f
	except Exception:
		dprint('invalid input file')
if outId > 0:
	dprint('use output', outId)
	try:
		f = open('stdout' + str(outId) + '.txt', 'w')
		sys.stdout = f
	except Exception:
		dprint('invalid output file')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
for _ in range(N):
	(a, b) = getIntList()
	r = (a - 1) * 9 + b
	print(r)


for task in range(int(input().strip())):
	(k, x) = [int(i) for i in input().strip().split(' ')]
	print((k - 1) * 9 + x)


TN = int(input())

def solution():
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)
while TN != 0:
	solution()
	TN -= 1


n = int(input())
while n > 0:
	(a, b) = [int(i) for i in input().split()]
	print(b + (a - 1) * 9)
	n -= 1


def ans(arr):
	(k, x) = (arr[0], arr[1])
	return 9 * (k - 1) + x
n = int(input())
for _ in range(n):
	a = list(map(int, input().strip().split()))
	print(ans(a))


test = int(input())
for testcase in range(test):
	arr = [int(x) for x in input().split()]
	(k, x) = (arr[0], arr[1])
	print(9 * (k - 1) + x)


n = int(input())
for i in range(0, n):
	Req = input().split(' ')
	print(9 * (int(Req[0]) - 1) + int(Req[1]))


def rlist():
	return list(map(int, input().split()))

def rdi():
	return int(input())
n = rdi()
for i in range(n):
	(x, y) = rlist()
	print(y + (x - 1) * 9)


for i in range(int(input())):
	s = input()
	a = s.split(' ')
	k = int(a[0])
	x = int(a[1])
	print(x + (k - 1) * 9)


for _ in range(int(input())):
	(k, n) = map(int, input().split())
	count = 0
	if k == 1:
		print(n)
	else:
		print(n + 9 * (k - 1))


que = int(input())
for i in range(que):
	string = input().split(' ')
	Ki = int(string[0]) - 1
	X = int(string[1])
	print(Ki * 9 + X)


t = int(input())
while t:
	(m, n) = map(int, input().split())
	print(9 * (m - 1) + n)
	t -= 1


for _ in range(int(input())):
	k = input().split()
	print(9 * (int(k[0]) - 1) + int(k[1]))


t = int(input())
for i in range(t):
	(k, n) = map(int, input().split())
	p = int(9 - n)
	print(k * n + (k - 1) * p)


n = int(input())
for i in range(0, n):
	(l, r) = map(int, input().split())
	if l == 1:
		print(r)
		continue
	print(9 * (l - 1) + r)


from math import *
from copy import *
from string import *
from sys import stdin
from itertools import *
from collections import Counter

def digSum(n):
	if n == 0:
		return 0
	if n % 9 == 0:
		return 9
	else:
		return n % 9
T = int(input())
for _ in range(T):
	(k, summ) = map(int, input().split())
	ans = summ + (k - 1) * 9
	print(ans)


tc = int(input())
for i in range(tc):
	(l, n) = map(int, input().split())
	p = int(9 - n)
	print(l * n + (l - 1) * p)


n = int(input())
for i in range(n):
	(k, x) = list(map(int, input().split()))
	if k - 1 > 0:
		fr = k - 1
		ans = fr * 10 + x - fr
		print(ans)
	else:
		print(x)


n = int(input())
(k, x) = ([], [])
for _ in range(n):
	arr = list(map(int, input().split()))
	k.append(arr[0])
	x.append(arr[1])
for j in range(n):
	print(9 * k[j] - (9 - x[j]))


for i in range(int(input())):
	(N, K) = map(int, input().split())
	Z = 9 * (N - 1) + K
	print(Z)


n = int(input())
for i in range(0, n):
	kx = input().split()
	k = int(kx[0])
	x = int(kx[1])
	ans = x + 9 * (k - 1)
	print(ans)


for _ in range(int(input())):
	(k, x) = [int(i) for i in input().split()]
	if k == 1:
		print(x)
	else:
		print(9 * (k - 1) + x)


n = int(input())
for i in range(n):
	(k, x) = list(map(int, input().split()))
	res = x + (k - 1) * 9
	print(res)


def sum_of_digits(n):
	if len(n) == 1:
		return int(n)
	else:
		total = 0
		for digit in n:
			total += int(digit)
		return sum_of_digits(str(total))

def finding_ancestor(k, x):
	k -= 1
	if k == 0:
		return x
	if k % 10 == 0:
		place = k // 10
		remain = 10
	else:
		place = k // 10 + 1
		remain = k % 10
	temp = 0
	index = 0
	start = 1
	end = start + 8 * place + (place - 1)
	start = (end - 8) * 10
	end *= 10
	starters = [x for x in range(start, end + 1, 10)]
	while index < len(starters) and temp < remain:
		if sum_of_digits(str(starters[index])) == x:
			temp += 2
		else:
			temp += 1
		index += 1
	index -= 1
	if temp == remain:
		if sum_of_digits(str(starters[index])) == x:
			return starters[index] + 9
		else:
			sd = sum_of_digits(str(starters[index]))
			if x > sd:
				return starters[index] + (x - sd)
			else:
				return starters[index] + 9 - (sd - x)
	elif temp == remain + 1:
		return starters[index]
test = int(input())
for x in range(test):
	(k, x) = list(map(int, input().split()))
	print(finding_ancestor(k, x))


def S(x):
	t = sum(map(int, list(str(x))))
	if len(str(t)) > 1:
		return S(t)
	else:
		return t
(n, s) = (int(input()), [])
for i in range(n):
	s.append(list(map(int, input().split())))
for i in s:
	print((i[0] - 1) * 9 + i[1])


a = int(input())
for i in range(a):
	(x, y) = list(map(int, input().split()))
	r = y + (x - 1) * 9
	print(r)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	aa = [LI() for _ in range(n)]
	r = []
	for (k, x) in aa:
		r.append(x + 9 * (k - 1))
	return '\n'.join(map(str, r))
print(main())


tc = int(input())
while tc != 0:
	tc -= 1
	(a, b) = map(int, input().split())
	print(9 * (a - 1) + b)


import math
n = int(input())
for i in range(n):
	(k, x) = list(map(int, input().split()))
	print(x + 9 * (k - 1))


n = int(input())
for N in range(n):
	x = [int(i) for i in input().split()]
	ans = 9 * int(x[0] - 1) + int(x[1])
	print(ans)


t = int(input())
for i in range(0, t):
	(k, x) = [int(y) for y in input().split()]
	print(9 * k - (9 - x))


def func(k, x):
	return x + (k - 1) * 9
n = int(input())
for i in range(n):
	s = input().split()
	print(func(int(s[0]), int(s[1])))


from sys import stdin, stdout
from collections import defaultdict, Counter
import math
I = stdin.readline
P = stdout.write
q = int(I())
for _ in range(q):
	(k, x) = map(int, I().split())
	print(9 * (k - 1) + x)


n = int(input())
for i in range(0, n):
	x = input().strip().split()
	x = list(x)
	c = int(x[1]) + 9 * (int(x[0]) - 1)
	print(c)


def cal(n):
	while n > 9:
		ans = 0
		while n > 0:
			ans += n % 10
			n //= 10
		n = ans
	return n
for i in range(int(input())):
	(k, x) = map(int, input().split())
	print((k - 1) * 9 + x)


q = int(input())
while q > 0:
	(k, n) = map(int, input().split())
	print(9 * k + n - 9)
	q -= 1


t = int(input())
for _ in range(0, t):
	(k, x) = map(int, input().split())
	tn = x + (k - 1) * 9
	print(tn)


t = int(input())
while t:
	(k, x) = map(int, input().split())
	print(9 * (k - 1) + x)
	t -= 1


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	count = 1
	if a == 1:
		print(b)
	else:
		print(b + (a - 1) * 9)


import atexit
import io
import sys
INP = sys.stdin.read().splitlines()
input = iter(INP).__next__
OUT = io.StringIO()
sys.stdout = OUT

@atexit.register
def write():
	sys.__stdout__.write(OUT.getvalue())
n = int(input())
for i in range(n):
	(k, x) = map(int, input().split())
	print(9 * (k - 1) + x)


import math
import os
import random
import re
import sys
for a0 in range(int(input())):
	(k, x) = map(int, input().split())
	if k == 1:
		print(x)
	else:
		print(x + (k - 1) * 9)


n = int(input())
for i in range(0, n):
	p = input().rstrip().split(' ')
	k = int(p[0])
	x = int(p[1])
	print(9 * (k - 1) + x)


import sys
import math

def read_int():
	return int(input().strip())

def read_int_list():
	return list(map(int, input().strip().split()))

def read_string():
	return input().strip()

def read_string_list(delim=' '):
	return input().strip().split(delim)
q = read_int()
for _ in range(q):
	(k, x) = read_int_list()
	print(x + (k - 1) * 9)


from sys import stdin
for _ in range(int(input())):
	(n, m) = map(int, stdin.readline().rstrip().split(' '))
	print((n - 1) * 9 + m)


q = int(input())
for _ in range(q):
	(k, x) = map(int, input().split())
	if x != 9:
		print((k - 1) * 9 + x)
	else:
		print(k * 9)


import sys
import math
import random
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(k, x) = invr()
	n = x + (k - 1) * 9
	print(n)