import sys
def FastInt(zero=0):
    _ord, nums, num, neg = lambda x: x, [], zero, False
    i, s = 0, sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b"0"[0]:num = 10 * num + _ord(s[i]) - 48
            elif s[i] == b"-"[0]:neg = True
            elif s[i] != b"\r"[0]:
                nums.append(-num if neg else num)
                num, neg = zero, False
            i += 1
    except IndexError:
        pass
    if s and s[-1] >= b"0"[0]: nums.append(-num if neg else num)
    return nums
inp=FastInt();ii=0
def fin(size=None):
	global ii
	if size==None:
		ni=ii;ii+=1
		return inp[ni]
	else:
		ni=ii;ii+=size
		return inp[ni:ni+size]
_T_=fin()
for _t_ in range(_T_):
    n,k=fin(2)
    if k>n:
        print(k-n)
    else:
        if k%2:
            if n%2:
                print(0)
            else:
                print(1)
        else:
            if n%2:
                print(1)
            else:
                print(0)


import sys
def FastInt(zero=0):
    _ord, nums, num, neg = lambda x: x, [], zero, False
    i, s = 0, sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b"0"[0]:num = 10 * num + _ord(s[i]) - 48
            elif s[i] == b"-"[0]:neg = True
            elif s[i] != b"\r"[0]:
                nums.append(-num if neg else num)
                num, neg = zero, False
            i += 1
    except IndexError:
        pass
    if s and s[-1] >= b"0"[0]: nums.append(-num if neg else num)
    return nums
inp=FastInt();_Index=0
def fin(size=None):
	global _Index
	if size==None:
		ni=_Index;_Index+=1
		return inp[ni]
	else:
		ni=_Index;_Index+=size
		return inp[ni:ni+size]
_T_=fin()
for _t_ in range(_T_):
    n,k=fin(2)
    if k>n:
        print(k-n)
    else:
        if k%2:
            if n%2:
                print(0)
            else:
                print(1)
        else:
            if n%2:
                print(1)
            else:
                print(0)


import sys
def FastInt(zero=0):
    _ord, nums, num, neg = lambda x: x, [], zero, False
    i, s = 0, sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b"0"[0]:num = 10 * num + _ord(s[i]) - 48
            elif s[i] == b"-"[0]:neg = True
            elif s[i] != b"\r"[0]:
                nums.append(-num if neg else num)
                num, neg = zero, False
            i += 1
    except IndexError:
        pass
    if s and s[-1] >= b"0"[0]: nums.append(-num if neg else num)
    return nums
inp=FastInt();_Index=0 #
def fin(size=None):
	global _Index
	if size==None:
		ni=_Index;_Index+=1
		return inp[ni]
	else:
		ni=_Index;_Index+=size
		return inp[ni:ni+size]
_T_=fin()
for _t_ in range(_T_):
    n,k=fin(2)
    if k>n:
        print(k-n)
    else:
        if k%2:
            if n%2:
                print(0)
            else:
                print(1)
        else:
            if n%2:
                print(1)
            else:
                print(0)


import sys
def FastInt(zero=0):
    _ord, nums, num, neg = lambda x: x, [], zero, False
    i, s = 0, sys.stdin.buffer.read()
    try:
        while True:
            if s[i] >= b"0"[0]:num = 10 * num + _ord(s[i]) - 48
            elif s[i] == b"-"[0]:neg = True
            elif s[i] != b"\r"[0]:
                nums.append(-num if neg else num)
                num, neg = zero, False
            i += 1
    except IndexError:
        pass
    if s and s[-1] >= b"0"[0]: nums.append(-num if neg else num)
    return nums

inp=FastInt();ii=0
_T_=inp[ii];ii+=1
for _t_ in range(_T_):
    n,k=inp[ii:ii+2];ii+=2
    if k>n:
        print(k-n)
    else:
        if k%2:
            if n%2:
                print(0)
            else:
                print(1)
        else:
            if n%2:
                print(1)
            else:
                print(0)


import io,os
def FastInt(zero=0):
    _ord, nums, num, neg = lambda x: x, [], zero, False
    i, s = 0, io.BytesIO(os.read(0,os.fstat(0).st_size)).read()
    try:
        while True:
            if s[i] >= b"0"[0]:num = 10 * num + _ord(s[i]) - 48
            elif s[i] == b"-"[0]:neg = True
            elif s[i] != b"\r"[0]:
                nums.append(-num if neg else num)
                num, neg = zero, False
            i += 1
    except IndexError:
        pass
    if s and s[-1] >= b"0"[0]: nums.append(-num if neg else num)
    return nums

inp=FastInt();ii=0
_T_=inp[ii];ii+=1
for _t_ in range(_T_):
    n,k=inp[ii:ii+2];ii+=2
    if k>n:
        print(k-n)
    else:
        if k%2:
            if n%2:
                print(0)
            else:
                print(1)
        else:
            if n%2:
                print(1)
            else:
                print(0)


from sys import stdin, stdout

def soln(n,k):

   if k==0:

      if n%2==0:
         return 0
      else:
         return 1

   if k>=n:
      return(abs(k-n))

   else:
      return 0

t=int(stdin.readline())
while(t>0):
   t-=1
   n,k=[int(x) for x in stdin.readline().split()]
   print(soln(n,k))


from sys import stdin, stdout

def soln(n,k):

   if k>=n:
      return(abs(k-n))

   else:
      return ((n&1)^(k&1))

t=int(stdin.readline())
while(t>0):
   t-=1
   n,k=[int(x) for x in stdin.readline().split()]
   print(soln(n,k))


from sys import stdin, stdout

def soln(n,k):

   if k==0:

      if n%2==0:
         return 0
      else:
         return 1

   if k==n:
      return 0

   if k>n:
      return(abs(k-n))

   else:
      return 0

t=int(stdin.readline())
while(t>0):
   t-=1
   n,k=[int(x) for x in stdin.readline().split()]
   print(soln(n,k))


from sys import stdin, stdout

def soln(n,k):

   if k==n:
      return 0

   if k==0:

      if n%2==0:
         return 0
      else:
         return 1

   if k>n:
      return(abs(k-n))

   else:
      return 0

t=int(stdin.readline())
while(t>0):
   t-=1
   n,k=[int(x) for x in stdin.readline().split()]
   print(soln(n,k))


for _ in range(int(input())):
    n,k=[int(x) for x in input().split()]
    if k>=n:
        print(abs(n-k))
    elif k==0:
        if n%2==0:
            print(0)
        else:
            print(1)
    else:
        if (abs(k-n)%2==0):
            print(0)
        else:
            print(1)


for _ in range(int(input())):
    n,k=[int(x) for x in input().split()]
    if k>=n:
        print(abs(n-k))
    elif k==0:
        if n%2==0:
            print(0)
        else:
            print(1)
    else:
        print(abs(2*k-n))


for _ in range(int(input())):
    n,k=[int(x) for x in input().split()]
    if k>=n:
        if k<2*n:
            print(abs(n-k))
        else:
            print(n)
    elif k==0:
        if n%2==0:
            print(0)
        else:
            print(1)
    else:
        print(abs(2*k-n))


for _ in range(int(input())):
    n,k=[int(x) for x in input().split()]
    if k!=0:
        print(abs(n-k))
    else:
        if n%2==0:
            print(0)
        else:
            print(1)


for _ in range(int(input())):
    n,k=[int(x) for x in input().split()]
    if k>=n:
        print(abs(n-k))
    elif k==0:
        if n%2==0:
            print(0)
        else:
            print(1)
    else:
        if (abs(k-n)%2==0):
            print(0)
            print(1)


for _ in range(int(input())):
    n, k = map(int, input().split())
    if k == 0 and n % 2 == 1:
        print(1)
    else:
        print(max(0, k-n))


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


for _ in range(int(input())):
    n, k = map(int, input().split())
    if k >= n:
        print(k-n)
    elif (k % 2 == 0 and n % 2 == 1) or (k % 2 == 1 and n % 2 == 0):
        print(1)
    else:
        print(0)


for _ in range(int(input())):
    n, k = map(int, input().split())
    if (k == 0 and n % 2 == 1) or (k == 1 and n % 2 == 0):
        print(1)
    else:
        print(max(0, k-n))


for _ in range(int(input())):
    n, k = map(int, input().split())
    if k >= n:
        print(k-n)
    elif (k == 0 and n % 2 == 1) or (k == 1 and n % 2 == 0):
        print(1)
    else:
        print(0)


for _ in range(int(input())):
    n, k = map(int, input().split())
    if k >= n:
        print(k-n)
    elif k < n and ((k == 0 and n % 2 == 1) or (k == 1 and n % 2 == 0)):
        print(1)


# -*- coding: utf-8 -*-
"""
Created on Fri Aug 21 20:29:48 2020

@author: Yogesh Panjwani
"""

x=int(input())
s=0
for i in range(x):
    n,k=map(int,input().split())
    if n<=k:
        s=k-n
    else:
        for j in range(n+1):
            if abs((j-0)-(n-j))==k:
                s=0
                break
        else:
            s=n-k
    print(s)


# -*- coding: utf-8 -*-
"""
Created on Fri Aug 21 20:29:48 2020

@author: Yogesh Panjwani
"""

x=int(input())
s=0
for i in range(x):
    n,k=map(int,input().split())
    if n<=k:
        s=k-n
    else:
        if (n%2==0 and k%2!=0) or (n%2!=0 and k%2==0):
            s=1
        else:
            s=0

    print(s)


# -*- coding: utf-8 -*-
"""
Created on Fri Aug 21 20:29:48 2020

@author: Yogesh Panjwani
"""

x=int(input())
s=0
for i in range(x):
    n,k=map(int,input().split())
    if n<=k:
        s=k-n
    else:

        for j in range(n+1):
                if abs((j-0)-(n-j))==k:
                    s=0
                    break

        else:
            if n%2==0:
                s=n-k
            else:
                s=1

    print(s)


# -*- coding: utf-8 -*-
"""
Created on Fri Aug 21 20:29:48 2020

@author: Yogesh Panjwani
"""

x=int(input())
s=0
for i in range(x):
    n,k=map(int,input().split())
    if n<=k:
        s=k-n
    else:

        for j in range(n+1):
                if abs((j-0)-(n-j))==k:
                    s=0
                    print(j)
                    break

                else:
                    if n%2==0:
                        s=n-k
                    else:
                        s=1

    print(s)


def find_diff():
    n,k=input().split()
    n=int(n)
    k=int(k)
    if(n<k):
        print(k-n)
    else:
        print((n-k)%2)

t=int(input())
s=1
while(s<=t):
    find_diff()
    s+=1


def find_diff():
    n,k=input().split()
    n=int(n)
    k=int(k)
    if(n==k):
        print(0)
    elif(k==0 and n%2==0):
        print(0)
    elif(k==0 and n%2 != 0):
        print(1)
    else:
        print(abs(n-k))

t=int(input())
s=1
while(s<=t):
    find_diff()
    s+=1


def find_diff():
    n,k=input().split()
    n=int(n)
    k=int(k)
    if(n>=0 and n<=1000000 and k>=0 and k<=1000000 ):
        if(n==k):
            print(0)
        elif(k==0 and n%2==0):
            print(0)
        elif(k==0 and n%2 != 0):
            print(1)
        else:
            print(abs(n-k))

t=int(input())
s=1
while(s<=t):
    find_diff()
    s+=1


T = int(input())

for i in range(T):
    n, k = map(int, input().split())

    if k == 0:
        if n%2 == 0:
            print(0)
        else:
            print(1)
    else:
        if k > n:
            print(k-n)
        else:
            print(n-k)


def Solve(n, k):

    if n == k:
        return 0

    if n%2 == 0:

        if k%2 == 0:

            if n > k:
                return 0
            else:
                return (k-n)

        else:
            if n>k:
                return Solve(n-1, k)+1
            else:
                return Solve(n+1, k)+1

    else:

        if k%2 == 0:
            if n>k:
                return Solve(n-1, k)+1
            else:
                return Solve(n+1, k)+1

        else:

            if n>k:
                return 0
            else:
                return (k-n)

T = int(input())

for i in range(T):
    n, k = map(int, input().split())

    if k == 0:
        if n%2 == 0:
            print(0)
        else:
            print(1)

    else:
        print(Solve(n, k))


def Solve(n, k):

    if n == k:
        return 0

    if n%2 == 0:

        if k%2 == 0:

            if n > k:
                return 0
            else:
                return (k-n)

        else:
            if n>k:
                return Solve(n-1, k)+1
            else:
                return Solve(n+1, k)+1

    else:

        if k%2 == 0:
            if n>k:
                return Solve(n-1, k)+1
            else:
                return Solve(n+1, k)+1

        else:

            if n>k:
                return 0
            else:
                return (k-n)

T = int(input())

for i in range(T):
    n, k = map(int, input().split())

    if k == 0:

    else:
        print(Solve(n, k))


def Solve(n, k):

    if n == k:
        return 0

    if n%2 == 0:

        if k%2 == 0:

            if n > k:
                return (n-k)//2
            else:
                return (k-n)

        else:
            if n>k:
                return Solve(n-1, k)+1
            else:
                return Solve(n+1, k)+1

    else:

        if k%2 == 0:
            if n>k:
                return Solve(n-1, k)+1
            else:
                return Solve(n+1, k)+1

        else:

            if n>k:
                return (n-k)//2
            else:
                return (k-n)

T = int(input())

for i in range(T):
    n, k = map(int, input().split())

    if k == 0:
        if n%2 == 0:
            print(0)
        else:
            print(1)

    else:
        print(Solve(n, k))


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

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

def solve(){
	n,k = MI()
	if k>n:
		print(k-n)
	else:
		a = int(n%2 != k%2)
		print(a)
}

tests = 1
t = 1
if tests == 1:
	t = II()
for q in range(t):
	solve()


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

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

def solve():
	n,k = MI()
	if k>n:
		print(k-n)
	else:
		a = int(n%2 != k%2)
		print(a)

tests = 1
t = 1
if tests:
	t = II()
for q in range(t):
	solve()


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n,k = MI()
	if k>n:
		print(k-n)
	else:
		a = int(n%2 != k%2)
		print(a)


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	n,k = MI()
	print(n+k)


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

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

solve(){
	n,k = MI()
	if k>n:
		print(k-n)
	else:
		a = int(n%2 != k%2)
		print(a)
}

tests = 1
t = 1
if tests == 1:
	t = II()
for q in range(t):
	solve()


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

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

def solve():

tests = 1
t = 1
if tests:
	t = II()
for q in range(t):
	solve()


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

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

def solve():
	n,k = MI()
	if k>n:
		print(k-n)
	else:
		a = int(n%2 != k%2)
		print(a)

tests = 1
t = 1
if tests == 1:
	t = II()
for q in range(t):
	solve()


import sys
import math
def II():
	return int(sys.stdin.readline())

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

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

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

def solve()
	n,k = MI()
	if k>n:
		print(k-n)
	else:
		a = int(n%2 != k%2)
		print(a)

tests = 1
t = 1
if tests == 1:
	t = II()
for q in range(t):
	solve()


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
b=0
c=0
d=0
w=0
for i in range(x):
    y,z=invr()
    if z==0 and y%2==0:
        a.append(0)
    elif z==0 and y%2==1:
        a.append(1)
    else:
        b=z
        if abs(y-z)>abs(y-2*z) and y>z:
            while (y-z)>z:
                z+=b
                d=0
                while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
                    if ((abs(d-(z-d)))==b) and d<=z:
                        w=z
            d=0
            while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
            m=z
            if ((abs(d-(z-d)))==b):
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(z-y):
                        c=abs(z-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
            else:
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(w-y):
                        c=abs(w-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)

for i in a:
    print(i)


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
b=0
c=0
d=0
w=0
for i in range(x):
    y,z=invr()
    if z==0 and y%2==0:
        a.append(0)
    elif z==0 and y%2==1:
        a.append(1)
    else:
        b=z
        if abs(y-z)>abs(y-2*z) and y>z:
            while (y-z)>z:
                z+=b
                d=0
                while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
                    if ((abs(d-(z-d)))==b) and d<=z:
                        w=z
            d=0
            while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
            m=z
            if ((abs(d-(z-d)))==b):
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(z-y):
                        c=abs(z-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
            else:
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(w-y):
                        c=abs(w-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
        else:
            c=abs(y-z)
            a.append(c)

for i in a:
    print(i)


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
b=0
c=0
d=0
w=0
for i in range(x):
    y,z=invr()
    if z==0 and y%2==0:
        a.append(0)
    elif z==0 and y%2==1:
        a.append(1)
    else:
        b=z
        if abs(y-z)>abs(y-2*z) and y>z:
            while (y-z)>z:
                z+=b
                d=0
                while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
                    if ((abs(d-(z-d)))==b) and d<=z:
                        w=z
            d=0
            while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
            m=z
            if ((abs(d-(z-d)))==b):
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(z-y):
                        c=abs(z-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
            else:
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(w-y):
                        c=abs(w-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
        else:
            d=0
            while not((abs(d-abs(y-d)))==z) and d<=y:
                d+=1
            if (abs(d-abs(y-d)))==z:
                a.append(0)
            else:
                c=abs(y-z)
                a.append(c)
#2b-n-m=k, and 2b-n-m=-k

for i in a:
    print(i)


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
b=0
c=0
for i in range(x):
    y,z=invr()
    if z==0 and y%2==0:
        a.append(0)
    elif z==0 and y%2==1:
        a.append(1)
    else:
        b=z
        if abs(y-z)>abs(y-2*z) and y>z:
            while (y-z)>z:
                z+=b
            if abs(y-z)<z*0.5:
                c=abs(y-z)
                a.append(c)
            else:
                z+=b
                c=abs(y-z)
                a.append(c)
        else:
            c=abs(y-z)
            a.append(c)
for i in a:
    print(i)


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
b=0
c=0
d=0
w=0
for i in range(x):
    y,z=invr()
    if z==0 and y%2==0:
        a.append(0)
    elif z==0 and y%2==1:
        a.append(1)
    else:
        b=z
        if abs(y-z)>abs(y-2*z) and y>z:
            while (y-z)>z:
                z+=b
                d=0
                while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
                    if ((abs(d-(z-d)))==b) and d<=z:
                        w=z
            d=0
            while not((abs(d-(z-d)))==b) and d<=z:
                    d+=1
            m=z
            if ((abs(d-(z-d)))==b):
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(z-y):
                        c=abs(z-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
            else:
                d=0
                while not((abs(d-(m-d)))==b) and d<=m:
                    d=0
                    m+=b
                    while not((abs(d-(m-d)))==b) and d<=m:
                        d+=1
                if ((abs(d-(m-d)))==b):
                    if abs(m-y)>abs(w-y):
                        c=abs(w-y)
                        a.append(c)
                    else:
                        c=abs(m-y)
                        a.append(c)
        else:
            c=abs(y-z)
            a.append(c)
#2b-n-m=k, and 2b-n-m=-k

for i in a:
    print(i)


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
b=0
for i in range(x):
    y,z=invr()
    if z==0 and y%2==0:
        a.append(0)
    elif z==0 and y%2==1:
        a.append(1)
    else:
        b=abs(z-y)
        a.append(b)
for i in a:
    print(i)


import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))
x=inp()
a=[]
arv=0
for i in range(x):
    y,z=invr()
    if y>=z:
        if (y+z)%2==0:
            a.append(0)
        else:
            a.append(1)
    else:
        arv=abs(z-y)
        a.append(arv)
for i in a:
    print(i)


t = int(input())
for i in range(t):
    n, k = map(int, input().split())
    if n % 2 != 0 and k == 0:
        print('1')
    elif n % 2 == 0 and k == 0:
        print('0')
    elif k > 0:
        print(k - n)


t = int(input())

def ok(m, n, k):
    if abs(m - (n - m)) <= k:
        return True
    else:
        return False

for i in range(t):
    n, k = map(int, input().split())
    if n <= k:
        print(k - n)
    else:
        s = 0
        while True:
            l = 0
            r = n
            while r - l > 1:
                m = (r + l) // 2
                if ok(m, n, k):
                    l = m
                else:
                    r = m
            if abs(l - (n - l)) == k:
                print(s)
                break
            else:
                s += 1
                n += 1


t = int(input())
for i in range(t):
    n, k = map(int, input().split())
    if n % 2 != 0 and k == 0:
        print('1')
    elif n % 2 == 0 and k == 0:
        print('0')
    elif k > 0 and n != 0:
        print(k - n)
    else:
        print('0')


t = int(input())

def ok(m, n, k):
    if abs(m - (n - m)) <= k:
        return True
    else:
        return False

for i in range(t):
    n, k = map(int, input().split())
    if n < k:
        print(k - n)
    else:
        s = 0
        while True:
            l = 0
            r = n
            while r - l > 1:
                m = (r + l) // 2
                if ok(m, n, k):
                    l = m
                else:
                    r = m
            if abs(l - (n - l)) == k:
                print(s)
                break
            else:
                s += 1
                n += 1


#include <bits/stdc++.h>

using namespace std;

int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
    int x,k;
    cin>>k>>x;
    long long sum=(k-1)*9 + x;
    cout<<"\n";
}
return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
using namespace std;
int main(){
int n,m,ans;
cin>>n;
while (n>0){
n--;
int k,x;
cin>>k;
cin>>x;
m=(9*k)-9;
ans =m +x;
cout << ans<<endl;
  }
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
using namespace std;
int main(){
int n,m;
cin>>n;
while (n>0){
n--;
int k,x;
cin>>k;
cin>>x;
m=((k-1)*9)+x;
cout << m<<endl;
}

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
using namespace std;
int main(){
int n,m,ans;
cin>>n;
while (n>0){
n--;
int k,x;
cin>>k;
cin>>x;
m=(k-1)*9;
ans =m +x;
cout << ans<<endl;
}

}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <math.h>
using namespace std;
int main(){
long long n,m,ans;
cin>>n;

while (n--){

long long x,k;
cin>>k>>x;
m=9*(k-1)+x;
cout << m<<endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.141592653
int main()
{
	ll t;
	cin>>t;
	while(t--){
		ll k,x;k=1e12;x=5;
		cin>>k>>x;
		ll ans=((k-1)*9)+(x);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.141592653
int main()
{
	ll t;
	cin>>t;
	while(t--){
		ll k,x;

		cin>>k>>x;

		ll ans=((k-1)*9)+(x);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.141592653
int main()
{
	ll t;
	cin>>t;
	while(t--){
		ll k,x;
		cin>>k>>x;
		ll ans=((k-1)*9)+(x%9);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.141592653
int main()
{
	ll t;
	cin>>t;
	while(t--){
		ll k,x;
		cin>>k>>x;
		ll ans=((k-1)*9)+(x);
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  int t;
   cin >> t;
   while(t--)
   {
     ll k,x;
     cin >> k >> x;
     cout << ((k-1)*9 + x) << endl;
   }
}


#include<bits/stdioc++.h>
typedef long long ll;
using namespace std;
int main()
{
  int t;
   cin >> t;
   while(t--)
   {
     ll k,x;
     cin >> k >> x;
     cout << ((k-1)*9 + n) << endl;
   }
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
  int t;
   cin >> t;
   while(t--)
   {
     ll k,x;
     cin >> k >> x;
     cout << ((k-1)*9 + n) << endl;
   }
}


#include<bits/stdioc++.h>
typedef long long ll;
using namespace std;
int main()
{
  int t;
   cin >> t;
   while(t--)
   {
     ll k,x;
     cin >> k >> x;
     ll p=((k-1)*9 + n);
     cout << p << endl;
   }
}


#include<bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k,i=1,count=0;
		cin>>n>>k;
		while(count!=n)
		{
			if(i%9==k)
				count++;
			else if(i%9==0 && k==9)
				count++;
			i++;
		}
		cout<<--i<<"\n";
	}
}


#include<bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k,i=1,count=0;
		cin>>n>>k;
		while(count!=n)
		{
			if(i%9==k)
				count++;
			i++;
		}
		cout<<--i<<"\n";
	}
}


#include<bits/stdc++.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define ll long long
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		ll n,k,i=1,count=0;
		cin>>n>>k;
		ll x=k+9*(n-1);
		cout<<x<<"\n";
	}
}


	#include <algorithm>
	#include <vector>
	#include <string>
	#include <iostream>
	#include <queue>
	#include <deque>
	#include <cmath>

	using namespace std;

	typedef long long int64;

	queue<int64>mas;

	void fun() {
		int64 k, x, res;
		cin >> k >> x;
		res = x + (k - 1) * 9;
		cout << res << endl;
	}

	int main() {
		int64 n;
		cin >> n;

		for (int64 i = 0; i < n; i++)
		{
			fun();
		}

		cout << endl;
		//system("pause");
		return 0;
	}


	#include <algorithm>
	#include <vector>
	#include <string>
	#include <iostream>
	#include <queue>
	#include <deque>
	#include <cmath>

	using namespace std;

	typedef long long int64;

	queue<int64>mas;

	void fun() {
		int64 k, x, res;
		cin >> k >> x;
		res = x + (k - 1) * 9;
		cout << res << endl;
	}

	int64 main() {
		int64 n;
		cin >> n;

		for (int64 i = 0; i < n; i++)
		{
			fun();
		}

		cout << endl;
		//system("pause");
		return 0;
	}


	#include <algorithm>
	#include <vector>
	#include <string>
	#include <iostream>
	#include <queue>
	#include <deque>
	#include <cmath>

	using namespace std;

	typedef long long int64;

	queue<int64>mas;

	void fun() {
		int64 k, x, res;
		cin >> k >> x;
		res = x + (k - 1) * 9;
		cout << res << endl;
	}

	int64 main() {
		int64 n;
		cin >> n;

		for (int64 i = 0; i < n; i++)
		{
			fun();
		}

		cout << endl;
		system("pause");
		return 0;
	}


#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <deque>
#include <cmath>

using namespace std;

typedef long long int64;

queue<int>mas;

void fun() {
	int k, x, res;
	cin >> k >> x;
	res = x + (k - 1) * 9;
	cout << res << endl;
}

int main() {
	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		fun();
	}

	cout << endl;
	//system("pause");
	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,k,x;
    cin>>n;
    while(n--)
    {
        cin>>k>>x;
        cout<<(k-1)*9+x<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll digit(ll k,ll x)
{
    ll i=k;
    do
    {
        i=k--;
        while (i>9)
            i=i/10+i%10;
    } while (i!=x);
    return k+1;

}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,k,x;
    cin>>n;
    while(n--)
    {
        cin>>k>>x;
        k=k*9;
        cout<<digit(k,x)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll digit(ll k,ll x)
{
    ll i=k;
    do
    {
        i=k--;
        while (i>9)
            i=i/10+i%10;
    } while (i!=x);
    return k+1;
}
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,k,x;
    cin>>n;
    while(n--)
    {
        cin>>k>>x;
        k=k*9-(k-1);
        cout<<digit(k,x)<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,k,x,i;
    cin>>n;
    while(n--)
    {
        cin>>k>>x;
        k=k*9;
        do
        {
            i=k--;
            while (i>9)
                i=i/10+i%10;
        } while (i!=x);
        cout<<k+1<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 35;
int S[maxn];
int main(){
    int t;
    scanf("%d",&t);
    for(int i=1;i<=9;i++)S[i] = i;
    for (int i=10;i<=30;i++){
        int sum=0;
        int tmp=i;
        while(tmp){
            sum+=tmp%10;
            tmp/=10;
        }
        S[i]=S[sum];
        cout<< i<<" "<<S[i]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
long long k;
int T,x;
int main(){
	cin>>T;
    while(T--){
		scanf("%ld %d",&k,&x);
		printf("%ld \n",(k-1)*9+x);
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
int T,x;
int main(){
	cin>>T;
    while(T--){
		scanf("%ld %d",&k,&x);
		printf("%ld d\n",(k-1)*9+x);
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
int T,x;
int main(){
	cin>>T;
    while(T--){
		cin>>k>>x;
		cout<<(k-1)*9+x<<endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long k;
int T,x;
int main(){
    while(T--){
		scanf("%ld %d",&k,&x);
		printf("%ld d\n",(k-1)*9+x);
	}
    return 0;
}


    #include<bits/stdc++.h>
    using namespace std;

    int main()
    {
        int t=1;
        cin>>t;
        while(t--)
        {
            long long k,x;
            cin>>k>>x;
            cout<<9*(k-1)+x<<endl;
        }
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;

    int main()
    {
        int t=1;
        cin>>t;
        while(t--)
        {
            int k,x;
            cin>>k>>x;
            cout<<(long long)9*(k-1)+x<<endl;
        }
        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;

    int main()
    {
        int t=1;
        cin>>t;
        while(t--)
        {
            int k,x;
            cin>>k>>x;
            cout<<9*(k-1)+x<<endl;
        }
        return 0;
    }


/**
 *    Author  : Ador
 *    Created : 04.08.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#define pi acos(-1.0)
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;
    int t ; cin >> t ;
    while(t--)
    {
        ll k , x ; cin >> k >> x ;
        cout << ((k - 1) * 9 + x) << "\n" ;
    }
    return 0 ;
}


/**
 *    Author  : Ador
 *    Created : 04.08.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#define pi acos(-1.0)
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;
    int t ; cin >> t ;
    while(t--)
    {
        ll k , x ; cin >> k >> x ;
        while(--k) x += 9 ;
        cout << x << "\n" ;
    }
    return 0 ;
}


/**
 *    Author  : Ador
 *    Created : 04.08.2020
**/
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#define pi acos(-1.0)
typedef long long int ll ;
typedef unsigned long long int ull ;
using namespace std ;
int digital_root(ll x)
{
    string s = to_string(x) ;
    ll sum = 0 ;
    for(ll i = 0 ; i < s.size() ; ++i)
    {
        sum += (s[i] - 48) ;
    }
    if(sum > 9) return digital_root(sum) ;
    return sum ;
}
int main(void)
{
    ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ;
    //freopen("input.txt" , "r" , stdin) ;
    //freopen("output.txt" , "w" , stdout) ;
    int t ; cin >> t ;
    while(t--)
    {
        ll k , x ; cin >> k >> x ;
        ll n = 0 , cnt = 0 ;
        while(cnt < k)
        {
            if(digital_root(++n) == x) ++cnt ;
        }
        cout << n << "\n" ;
    }
    return 0 ;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--) {
		int k, x;
		cin >> k >> x;
		cout << 9*k+x-9 << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--) {
		int k, x;
		cin >> k >> x;
		cout << 9*k+x-9 << endl;
	}
	return 0;


#include <iostream>
using namespace std;

int main() {
	long t;
	cin >> t;
	while(t--) {
		long long k, x;
		cin >> k >> x;
		cout << 9*(k-1) + x << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin >> t;
	while(t--) {
		long k, x;
		cin >> k >> x;
		cout << 9*(k-1) + x << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int s(int x){
    int suma=0;
    while(x!=0){
        suma+=x%10;
        x/=10;
    }
    if(suma>=10) return s(suma);
    else return suma;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed<<setprecision(10);
    int t;
    cin>>t;
    for(int i=0; i<t; i++){
        int k, n, j=0, x=0;
        cin>>k>>n;
        while(x!=k){
            j++;
            if(s(j)==n) x++;
        }
        cout<<j<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed<<setprecision(10);
    int t;
    cin>>t;
    for(int i=0; i<t; i++){
        ll k, n;
        cin>>k>>n;
        ll ans=n;
        ans+=(k-1)*9;
        cout<<ans<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int s(int x){
    double n=(double)x;
    return (int)(n-9*floor((n-1)/9));
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed<<setprecision(10);
    int t;
    cin>>t;
    for(int i=0; i<t; i++){
        int k, n, j=0, x=0;
        cin>>k>>n;
        while(x!=k){
            j++;
            if(s(j)==n) x++;
        }
        cout<<j<<"\n";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed<<setprecision(10);
    int t;
    cin>>t;
    for(int i=0; i<t; i++){
        int k, n;
        cin>>k>>n;
        int  ans=n;
        for(int j=1; j<k; j++){
            ans+=9;
        }
        cout<<ans<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
int main(void)
{
    int k,x,t,i;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>k>>x;
        cout<<x+(k-1)*9<<"\n";
    }
    return 0;

}


#include<iostream>
using namespace std;
int main(void)
{
    long long k,x,t,i;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>k>>x;
        cout<<x+(k-1)*9<<"\n";
    }
    return 0;

}


#include<stdio.h>
using namespace std;
int main(void)
{
    int t,k,x,i;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>k>>x;
        cout<<x+(k-1)*9<<"\n";
    }
    return 0;

}


#include<iostream>
using namespace std;
int main(void)
{
    long int k,x,t,i;
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>k>>x;
        cout<<x+(k-1)*9<<"\n";
    }
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
int T,k,x;
int s(int i){
	if(i<10)return i;
	int ans=0;
	while(i){
		ans+=i%10;
		i/=10;
	}
	return s(ans);
}
int main(){
	cin>>T;
	while(T--){
		cin>>k>>x;
		for(int i=x;;i++){
			if(s(i)==x){
				k--;
				if(k==0){
					cout<<i<<endl;
					break;
				}
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int T,k,x;
int s(int i){
	if(i<10)return i;
	int ans=0;
	while(i){
		ans+=i%10;
		i/=10;
	}
	return s(ans);
}
int main(){
	cin>>T;
	while(T--){
		cin>>k>>x;
		for(int i=x;;i+=9){
			if(s(i)==x){
				k--;
				if(k==0){
					cout<<i<<endl;
					break;
				}
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
inline int read(){
    int s = 0, w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-'){
            w = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        s = (s << 1) + (s << 3) + (ch ^ 48);
        ch = getchar();
    }
    return s * w;
}
inline void write(register long long x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
int t;
int main(){
	t = read();
	while(t--){
		register int k, x;
		k = read(), x = read();
		write(9ll * (k - 1) + x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
inline int read(){
    int s = 0, w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-'){
            w = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        s = (s << 1) + (s << 3) + (ch ^ 48);
        ch = getchar();
    }
    return s * w;
}
inline void write(register long long x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
int t;
int main(){
	t = read();
	while(t--){
		register int k, x;
		k = read(), x = read();
		write(9ll * (k - 1) + x);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
inline long long read(){
    register long long s = 0, w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-'){
            w = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        s = (s << 1) + (s << 3) + (ch ^ 48);
        ch = getchar();
    }
    return s * w;
}
inline void write(register long long x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
int t;
int main(){
	t = read();
	while(t--){
		register long long k, x;
		k = read(), x = read();
		write(9ll * (k - 1) + x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
inline long long read(){
    int s = 0, w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-'){
            w = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        s = (s << 1) + (s << 3) + (ch ^ 48);
        ch = getchar();
    }
    return s * w;
}
inline void write(register long long x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
int t;
int main(){
	t = read();
	while(t--){
		register long long k, x;
		k = read(), x = read();
		write(9ll * (k - 1) + x);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int T,k,x;
int s(int i){
	if(i<10)return i;
	int ans=0;
	while(i){
		ans+=i%10;
		i/=10;
	}
	return s(ans);
}
int main(){
	cin>>T;
	while(T--){
		cin>>k>>x;
		x+=(k-1)*9;
		cout<<x<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long T,k,x;
int main(){
	cin>>T;
	while(T--){
		cin>>k>>x;
		x+=(k-1)*9;
		cout<<x<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
inline long long read(){
    int s = 0, w = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-'){
            w = -1;
        }
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        s = (s << 1) + (s << 3) + (ch ^ 48);
        ch = getchar();
    }
    return s * w;
}
inline void write(register long long x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9){
        write(x / 10);
    }
    putchar(x % 10 + '0');
}
int t;
int main(){
	t = read();
	while(t--){
		register long long k, x;
		k = read(), x = read();
		write(9ll * (k - 1) + x);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
class gfg
{
    public:
    int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }
};
const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y,k;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {
	gfg g;

	for(cin>>tr;tr--;){
		cin>>k>>y;sum=0;
		for(int i=1; i<10000000000000; i++){
            a=i;
            b=a;
            while(b>9){
                b=g.getSum(b);
            }
            if(g.getSum(b)==y){
                sum++;i+=8;
                //cout<<a<<" ";
            }
            if(sum==k){
                cout<<a<<endl;break;
            }
	    }
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
class gfg
{
    public:
    int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }
};
const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y,k;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {
	gfg g;

	for(cin>>tr;tr--;){
		cin>>k>>y;sum=0;
		for(int i=1; i<100000; i++){
            a=i;
            b=a;
            while(b>9){
                b=g.getSum(b);
            }
            if(g.getSum(b)==y){
                sum++;
                //cout<<a<<" ";
            }
            if(sum==k){
                cout<<a<<endl;break;
            }
	    }
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
class gfg
{
    public:
    int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }
};
const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y,k;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {
	gfg g;

	for(cin>>tr;tr--;){
		cin>>k>>y;sum=0;
		for(int i=1; i<100000; i++){
            a=i;
            b=a;
            while(b>9){
                b=g.getSum(b);
            }
            if(g.getSum(b)==y){
                sum++;i+=5;
                //cout<<a<<" ";
            }
            if(sum==k){
                cout<<a<<endl;break;
            }
	    }
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
class gfg
{
    public:
    int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }
};
const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y,k;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {
	gfg g;

	for(cin>>tr;tr--;){
		cin>>k>>y;sum=0;
		for(int i=1; i<100000; i++){
            a=i;
            b=a;
            while(b>9){
                b=g.getSum(b);
            }
            if(g.getSum(b)==y){
                sum++;i+=3;
                //cout<<a<<" ";
            }
            if(sum==k){
                cout<<a<<endl;break;
            }
	    }
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
class gfg
{
    public:
    int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }
};
const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y,k;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {
	gfg g;

	for(cin>>tr;tr--;){
		cin>>k>>y;sum=0;
		for(int i=1; i<10000000000000; i++){
            a=i;
            b=a;
            while(b>9){
                b=g.getSum(b);
            }
            if(g.getSum(b)==y){
                sum++;i+=4;
                //cout<<a<<" ";
            }
            if(sum==k){
                cout<<a<<endl;break;
            }
	    }
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}

const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {

	for(cin>>tr;tr--;){
		cin>>x>>y;
		cout<<y<<endl;
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include <bits/stdc++.h>
#include <string.h>
#include<math.h>
#include<iostream>

using namespace std;
bool isPrime(int n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (int i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
class gfg
{
    public:
    int getSum(int n)
    {
    int sum = 0;
    while (n != 0)
    {
     sum = sum + n % 10;
     n = n/10;
    }
 return sum;
 }
};
const int N=1e5+7;
long long l,tr,n,sum,mini,maxi,a,b,c,x,y,k;
float m;
long long t[N];
set <int> vis;
vector<int> v;

int main() {
	gfg g;

	for(cin>>tr;tr--;){
		cin>>k>>y;sum=y;
		sum+=(k-1)*9;
		cout<<sum<<endl;
	}
}
/*
for(int i=0; i<n; i++){

	}
*/


#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#define N (1<<20)
using namespace std;
long long n, T;
long long q, w;
int main() {
	scanf("%lld", &T);
	while (T--) {
		scanf("%lld%lld", &q, &w);
		printf("%lld\n", q * 9 + w - 9);
	}
}


#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#define N (1<<20)
using namespace std;
int n, T;
int q, w;

int main() {
	scanf("%d", &T);
	while (T--) {
		scanf("%d%d", &q, &w);
		printf("%lld\n", q * 9 + w - 9);
	}
}


#include<iostream>

using namespace std;

int main() {

	int N;
	cin >> N;
	for (int i = 0;i < N;i++) {

		int a, b;
		cin >> a >> b;
		long long Ans = (a - 1) * 9 + b;
		cout << Ans << '\n';

	}

	return 0;
}


#include<iostream>

using namespace std;

int main() {

	int N;
	cin >> N;
	for (int i = 0;i < N;i++) {

		long long a, b;
		cin >> a >> b;
		long long Ans = (a - 1) * 9 + b;
		cout << Ans << '\n';

	}

	return 0;
}


//"  واما من امن وعمل صالحا فله جزاء الحسنى وسنقول له من امرنا يسرى"

#include<iostream>
#include<algorithm>
#include<string>
#include  <vector>
#include <cmath>
#include <functional>
#include <queue>
using namespace std;

int compare(pair<int, int> p1, pair <int, int> p2)
{
	if (p1.second == p2.second)
		return p1.first < p2.first;
	return p1.second < p2.second;
}

long long power[30];
long long FastPower(long long a, long long b)
{
	long long x = 1;
	while (b)
	{
		if (!(b % 2))
		{
			a *= a;
			b = b / 2;
		}
		else
		{
			x *= a;
			b--;
		}

	}

	return x;

}

int main()
{

	int n;
	cin >> n;
	while (n--)
	{
		long long k, x;
		cin >> k >> x;
		k--;
		k = k * 9;
		cout << k + x << endl;
	}

}


#include <stdio.h>

int n;
long long x, k, ans;

int main() {
	scanf("%d", &n);
	while (n--) {
		scanf("%lld %lld", &k, &x);
		ans = (k - 1) * 9 + x;
		printf("%lld\n", ans);
	}
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <string.h>
#include <set>
#include <queue>
#include <map>
#include <stack>

using namespace std;

const int INF = (int)1e9;

int main() {
	int n;
	cin >> n;
	while (n--) {
		long long k, x;
		cin >> k >> x;
		cout << 9 * (k - 1) + x << endl;
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	size_t n; cin >> n;

	do
	{
		unsigned long long k, x; cin >> k >> x;

		cout << (x + (k - 1) * 9) << '\n';
	}
	while (--n);

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>

using namespace std;
const long long inf = 1e9;
const long double pi = 3.141592;
typedef long long ll;
const long long mod1 = 1e9 + 7;
int main() {
	ll n;
	cin >> n;
	ll k, x;
	for (int i = 1; i <= n; i++) {
		cin >> k >> x;
		cout << x + 9 * (k-1)<<"\n";
	}

//system("pause>nul");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
const int mod =1e9+7;

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		ll t1, t2;
		cin >> t1 >> t2;
		cout << t2 + 9 * (t1 - 1) << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <clocale>
#include <bitset>
#include <cstring>
#include <memory.h>
#include <numeric>
#include <iomanip>
#include <stack>
#include <cstdlib>
#include <list>

using namespace std;

int number_root(int num)
{
	int res = 0;
	while (num)
	{
		res += num % 10;
		num /= 10;
	}
	if (res >= 10)
		return number_root(res);
	else
		return res;
}
int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;

	for(int i = 0; i < n; i++)
	{
		long long k, x;
		cin >> k >> x;
		cout << k * 9 - (9 - x) << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
#include <map>
#include <queue>
#include <clocale>
#include <bitset>
#include <cstring>
#include <memory.h>
#include <numeric>
#include <iomanip>
#include <stack>
#include <cstdlib>
#include <list>

using namespace std;

int number_root(int num)
{
	int res = 0;
	while (num)
	{
		res += num % 10;
		num /= 10;
	}
	if (res >= 10)
		return number_root(res);
	else
		return res;
}
int main() {

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;

	for(int i = 0; i < n; i++)
	{
		int k, x;
		cin >> k >> x;
		cout << k * 9 - (9 - x) << endl;
	}
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <sstream>
#include <string>

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int i = k; i < n; i++)
#define debug printf("Executed ");
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);

// Solution

ll n, k, x;

int main() {
    scanf("%I64d", &n);

    while (n--) {
        scanf("%I64d %I64d", &k, &x);

        printf("%I64d\n", k * 9 - (9 - x));
    }
}


#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <utility>
using namespace std;
inline int mmin(int a, int b) { return (a > b) ? b : a; }
inline int mmax(int a, int b) { return (a > b) ? a : b; }

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long k, x;
		cin >> k >> x;
		long long ans = (k - 1) * 9 + x;
		cout << ans << endl;
	}
}


#if 1
#pragma GCC optimize ("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <queue>
#include <stack>
#include <string.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

void solve() {
	int a, b;
	cin >> a >> b;

	ll res = 0;
	ll col = (a - 1) * 9 + b;

	cout << col << endl;
}

#define name "lepus"

int main() {
	//ios_base::sync_with_stdio(false);
	//freopen(name".in","r",stdin);
	//freopen(name".out","w",stdout);
	//cout.setf(ios::fixed);
	//cout.precision(6);
	int af = 1;
	cin >> af;
	//scanf("%d", &af);
	//test();
	//int g = 1;

	while(af-- > 0) {
		//cout << "Test " << g++ << endl;
		solve();
	}
	return 0;
}
#endif


#if 1
#pragma GCC optimize ("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <queue>
#include <stack>
#include <string.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()

void solve() {
	ll a, b;
	cin >> a >> b;

	ll res = 0;
	ll col = (a - 1) * 9 + b;

	cout << col << endl;
}

#define name "lepus"

int main() {
	//ios_base::sync_with_stdio(false);
	//freopen(name".in","r",stdin);
	//freopen(name".out","w",stdout);
	//cout.setf(ios::fixed);
	//cout.precision(6);
	int af = 1;
	cin >> af;
	//scanf("%d", &af);
	//test();
	//int g = 1;

	while(af-- > 0) {
		//cout << "Test " << g++ << endl;
		solve();
	}
	return 0;
}
#endif


#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace::std;

int digit_root(int s)
{
	int summ = 0;
	while (s != 0)
	{
		summ += s % 10;
		s /= 10;
	}
	if (summ >= 10)
		return digit_root(summ);
	else return summ;
}

void main()
{

	int q; cin >> q;//Кол-во задач пети 1000 max

	for (int i = 0; i < q; i++)
	{
		unsigned long long exp;//10^12 max переделать на строки
		int root;//10^1 max
		cin >> exp;
		cin >> root;

		cout << 9 * (exp - 1) + root << endl;
	}

}


#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace::std;

int digit_root(int s)
{
	int summ = 0;
	while (s != 0)
	{
		summ += s % 10;
		s /= 10;
	}
	if (summ >= 10)
		return digit_root(summ);
	else return summ;
}

void main()
{

	int q; cin >> q;//Кол-во задач пети 1000 max

	for (int i = 0; i < q; i++)
	{
		int exp;//10^12 max переделать на строки
		int root;//10^1 max
		cin >> exp;
		cin >> root;

		cout << 9 * (exp - 1) + root << endl;
	}

}


#include<iostream>
using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long k, x;
		cin >> k >> x;
		cout << (k - 1) * 9 + x << endl;
	}
	//system("pause>n");
}


#include <iostream>
#include <vector>
#include <stdlib.h>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <cmath>
#include <time.h>
using namespace std;

#define INIT ios::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL)

int main()
{
    INIT;
    int n;
    cin>>n;
    while(n--)
    {
        long long k;
        int x ;
        cin>>k>>x;
        cout<< (k - 1) * 9 + x<<endl;
    }
}


#include <iostream>
using namespace std;
int main()
{
    int n,x[1000];
    long long k[int(1e3)];
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> k[i] >> x[i];
    }
    for (int i=0; i<n; i++)
    {
        cout << (x[i] + ((k[i]-1) * 9)) << endl;
    }
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MAX_N 350
typedef long long LL;
int main(void)
{
	int T,k,n;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d %d",&k,&n);
		printf("%d\n",(k-1)*9+n);
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define MAX_N 350
typedef long long LL;
int main(void)
{
	LL T,k,n;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld %lld",&k,&n);
		printf("%lld\n",(k-1)*9+n);
	}
	return 0;
}


#include <iostream>

using namespace std;

int main()
{

	int n;
	cin >> n;
	long long x, k;
	for (int i = 0; i < n; i++)
	{

		cin >> x >> k;
		cout << ((x - 1) * 9) + k << endl;
	}

	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int n,x;
	long long k;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%I64d%d",&k,&x);
		printf("%I64d\n",9*(k-1)+x);
	}
}


#include<iostream>
#include<cstdio>
using namespace std;
int main(void)
{
	int n,k,x;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&k,&x);
		printf("%d\n",9*(k-1)+x);
	}
}


#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main()
{
  long long n,k,x;
  cin>>n;
  for(long long i=0;i<n;i++)
  {
    cin>>k>>x;
    cout<<x+(k-1)*9<<endl;
  }
}


// test1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <limits>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int i = 0;
	vector<long> ans;
	while (i != n)
	{
		long k, x;
		cin >> k >> x;
		ans.push_back(9 * (k - 1) + x);
		i++;
	}
	for (long p : ans)
	{
		cout << p << endl;
	}
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


// test1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <limits>
#include <vector>
#include <bitset>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{

	int n;
	cin >> n;
	int i = 0;
	vector<long long> ans;
	while (i != n)
	{
		long long k, x;
		cin >> k >> x;
		ans.push_back(9 * (k - 1) + x);
		i++;
	}
	for (long long p : ans)
	{
		cout << p << endl;
	}
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


// test1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <limits>
#include <vector>
#include <bitset>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int i = 0;
	vector<int> ans;
	while (i != n)
	{
		int k, x;
		cin >> k >> x;
		ans.push_back(9 * (k - 1) + x);
		i++;
	}
	for (int p : ans)
	{
		cout << p << endl;
	}
	return 0;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started:
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


#include<iostream>
using namespace std;
int main()
{
	long long n,k,x;
	scanf("%lld",&n);
	for(long long i=0;i<n;i++)
	{
		scanf("%lld%lld",&k,&x);
		printf("%d",x);
		for(int i=1;i<k;i++)
		{
			printf("0");
		}
		printf("\n");
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	long long n,a,b;
	scanf("%lld",&n);
	while(n--)
	{
		scanf("%lld%lld",&a,&b);
		printf("%lld\n",(a-1)*9+b);
	}
	return 0;
}


#include<iostream>
#define ll long long
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	while(n--) {
		ll k, m;
		cin>>k>>m;
		cout<<(9*(k-1) + m)<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	while(n--) {
		ll k, m;
		cin>>k>>m;
		cout<<(9*(k-1) + m)<<endl;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<iomanip>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include <fstream>
#include <set>
#include <list>
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define all(g) g.begin(),g.end()
#define allr(g) g.rbegin(),g.rend()
#define re(x)   return cout<<x,0
#define in(n)for(int i=0;i<n;i++)cin>>v[i];
#define loop(n)for(int i=0;i<n;i++)
#define matar 	ios_base::sync_with_stdio(false); cin.tie(NULL);
#define me(x,v) memset(x,v,sizeof(x))
#define endl '\n'
ll GCD(ll a, ll b){ return(b == 0) ? a : GCD(b, a%b); }
ll LCM(ll a, ll b)
{
	ll temp = GCD(a, b);

	return temp ? (a / temp * b) : 0;
}
ll oo = 1e18;
ll const M = 1e6, N = 3e6 + 7;
ll  n, m, sum, t, c, k;
ll x, y;
int main()
{
	matar
		cin >> t;
	string s;
	while (t--)
	{
		cin >> n>>m;
		n--;
		cout << n * 9 + m << endl;;

	}

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <bitset>

using namespace std;

typedef long long LL;
typedef long double LD;

int main() {
	int q;
	scanf("%d", &q);
	while (q--) {
		LL k, x;
		scanf("%I64d %I64d", &k, &x);
		printf("%I64d\n", (k - 1) * 9 + x);
	}
	return 0;
}


#include<iostream>
using namespace std;
int main();
{
  int t,i;
    long long int k,n;
 for(i=0;i<t;i++)
 {
 cin>>k>>n;
    cout<<(k-1)*9+n<<"\n";
 }
    return 0;
}


//Cf-2B.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long lovelive;
const int inf = INT_MAX;
const double pai = acos(-1.0);
const double gold = (sqrt(5.0) - 1.0) / 2.0;
int base_arr[1117][1117], dp[1117][1117][4];

void init()
{
    memset(base_arr, 0, sizeof(base_arr));
    memset(dp, 0, sizeof(dp));
return ;
}

void printpath(int kind, int n, int x, int y)
{
    if(x == 1 && y == 1) return ;
    if(dp[x][y][kind] == 0)
    {
        printpath(kind, n, x - 1, y);
        printf("D");
    }
    else if(dp[x][y][kind] == 1)
    {
        printpath(kind, n, x, y - 1);
        printf("R");
    }
return ;
}
int main(int argc, char const *argv[])
{
    // freopen("in.in", "r", stdin);
    int n, i, j, k, flag, zx, zy;
    scanf("%d", &n);
    {
        init(), flag = 0;
        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                scanf("%d", &base_arr[i][j]);
                if(base_arr[i][j] == 0 && !flag)
                {
                    flag = 1;
                    zx = i, zy = j;
                }
            }
        }

        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                if(i == 1 && j == 1)
                {
                    dp[i][j][2] = dp[i][j][3] = 0;
                    continue;
                }
                if(i == 1)
                {
                    dp[i][j][0] = dp[i][j - 1][0];
                    dp[i][j][1] = dp[i][j - 1][1];
                    dp[i][j][2] = dp[i][j][3] = 1;
                }
                else if(j == 1)
                {
                    dp[i][j][0] = dp[i - 1][j][0];
                    dp[i][j][1] = dp[i - 1][j][1];
                    dp[i][j][2] = dp[i][j][3] = 0;
                }
                else
                {
                    if(dp[i - 1][j][0] < dp[i][j - 1][0])
                    {
                        dp[i][j][0] = dp[i - 1][j][0];
                        dp[i][j][2] = 0;
                    }
                    else
                    {
                        dp[i][j][0] = dp[i][j - 1][0];
                        dp[i][j][2] = 1;
                    }
                    if(dp[i - 1][j][1] < dp[i][j - 1][1])
                    {
                        dp[i][j][1] = dp[i - 1][j][1];
                        dp[i][j][3] = 0;
                    }
                    else
                    {
                        dp[i][j][1] = dp[i][j - 1][1];
                        dp[i][j][3] = 1;
                    }
                }
                int tmp = base_arr[i][j];
                while(tmp % 2 == 0)
                {
                    dp[i][j][0] += 1;
                    tmp /= 2;
                }
                tmp = base_arr[i][j];
                while(tmp % 5 == 0)
                {
                    dp[i][j][1] += 1;
                    tmp /= 5;
                }
            }
        }
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][0]);
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][1]);
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][2]);
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][3]);
        //     }
        //     cout << endl;
        // }
        if(flag == 1)
        {
            printf("1\n");
            for(i = 1; i <= zx; ++i)
            {
                printf("D");
            }
            for(i = zy; j <= n; ++j)
            {
                printf("R");
            }
            printf("\n");
        }
        else
        {
            if(dp[n][n][0] < dp[n][n][1])
            {
                // cout << "adgdf" << endl;
                printf("%d\n", dp[n][n][0]);
                printpath(2, n, n, n);
            }
            else
            {
                // cout << "frbgr" << endl;
                printf("%d\n", dp[n][n][1]);
                printpath(3, n, n, n);
            }
            printf("\n");
        }
    }
return 0;
}


//Cf-2B.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long lovelive;
const int inf = INT_MAX;
const double pai = acos(-1.0);
const double gold = (sqrt(5.0) - 1.0) / 2.0;
int base_arr[1117][1117], dp[1117][1117][4], mat[1117][1117][2];

void printpath(int kind, int n, int x, int y)
{
    if(x == 1 && y == 1) return ;
    if(dp[x][y][kind] == 0)
    {
        printpath(kind, n, x - 1, y);
        printf("D");
    }
    else if(dp[x][y][kind] == 1)
    {
        printpath(kind, n, x, y - 1);
        printf("R");
    }
return ;
}

int main(int argc, char const *argv[])
{
    // freopen("in.in", "r", stdin);
    int n, i, j, k, flag, zx, zy;
    scanf("%d", &n);
    {
        flag = 0;
        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                scanf("%d", &base_arr[i][j]);
                int tmp = base_arr[i][j];
                if(base_arr[i][j] % 2 == 0)
                {
                    while(tmp % 2 == 0)
                    {
                        mat[i][j][0] += 1;
                        tmp /= 2;
                    }
                }
                if(base_arr[i][j] % 5 == 0)
                {
                    tmp = base_arr[i][j];
                    while(tmp % 5 == 0)
                    {
                        mat[i][j][1] += 1;
                        tmp /= 5;
                    }
                }
                if(base_arr[i][j] == 0 && !flag)
                {
                    flag = 1;
                    zx = i, zy = j;
                }
            }
        }
        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                if(i == 1)
                {
                    dp[i][j][0] = dp[i][j - 1][0];
                    dp[i][j][1] = dp[i][j - 1][1];
                    dp[i][j][2] = dp[i][j][3] = 1;
                }
                else if(j == 1)
                {
                    dp[i][j][0] = dp[i - 1][j][0];
                    dp[i][j][1] = dp[i - 1][j][1];
                    dp[i][j][2] = dp[i][j][3] = 0;
                }
                else
                {
                    if(dp[i - 1][j][0] < dp[i][j - 1][0])
                    {
                        dp[i][j][0] = dp[i - 1][j][0];
                        dp[i][j][2] = 0;
                    }
                    else
                    {
                        dp[i][j][0] = dp[i][j - 1][0];
                        dp[i][j][2] = 1;
                    }
                    if(dp[i - 1][j][1] < dp[i][j - 1][1])
                    {
                        dp[i][j][1] = dp[i - 1][j][1];
                        dp[i][j][3] = 0;
                    }
                    else
                    {
                        dp[i][j][1] = dp[i][j - 1][1];
                        dp[i][j][3] = 1;
                    }
                }
                dp[i][j][0] += mat[i][j][0];
                dp[i][j][1] += mat[i][j][1];
            }
        }
        dp[1][1][2] = dp[1][1][3] = 0;
        if(flag == 1)
        {
            printf("1\n");
            for(i = 1; i <= zx; ++i)
            {
                printf("D");
            }
            for(i = zy; j <= n; ++j)
            {
                printf("R");
            }
            printf("\n");
        }
        else
        {
            if(dp[n][n][0] < dp[n][n][1])
            {
                printf("%d\n", dp[n][n][0]);
                printpath(2, n, n, n);
            }
            else
            {
                printf("%d\n", dp[n][n][1]);
                printpath(3, n, n, n);
            }
            printf("\n");
        }
    }
return 0;
}


//Cf-2B.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long lovelive;
const int inf = INT_MAX;
const double pai = acos(-1.0);
const double gold = (sqrt(5.0) - 1.0) / 2.0;
int base_arr[1117][1117], dp[1117][1117][4];

void init()
{
    memset(base_arr, 0, sizeof(base_arr));
    memset(dp, 0, sizeof(dp));
return ;
}

void printpath(int kind, int n)
{
    int i = n, j = n, k;
    while(i != 1 || j != 1)
    {
        if(dp[i][j][kind] == 0)
        {
            if(j == 1)
            {
                printf("D"); i -= 1;
            }
            else
            {
                printf("R"); j -= 1;
            }
        }
        else if(dp[i][j][kind] == 1)
        {
            if(i == 1)
            {
                printf("R"); j -= 1;
            }
            else
            {
                printf("D"); i -= 1;
            }
        }
        // cout << i << " " << j << endl;
    }
    printf("\n");
return ;
}
int main(int argc, char const *argv[])
{
    // freopen("in.in", "r", stdin);
    int n, i, j, k, flag, zx, zy;
    while(scanf("%d", &n) != EOF)
    {
        init(), flag = 0;
        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                scanf("%d", &base_arr[i][j]);
                if(base_arr[i][j] == 0 && !flag)
                {
                    flag = 1;
                    zx = i, zy = j;
                }
            }
        }

        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                if(i == 1)
                {
                    dp[i][j][0] = dp[i][j - 1][0];
                    dp[i][j][1] = dp[i][j - 1][1];
                    dp[i][j][2] = dp[i][j][3] = 1;
                }
                else if(j == 1)
                {
                    dp[i][j][0] = dp[i - 1][j][0];
                    dp[i][j][1] = dp[i - 1][j][1];
                    dp[i][j][2] = dp[i][j][3] = 0;
                }
                else
                {
                    if(dp[i - 1][j][0] < dp[i][j - 1][0])
                    {
                        dp[i][j][0] = dp[i - 1][j][0];
                        dp[i][j][2] = 0;
                    }
                    else
                    {
                        dp[i][j][0] = dp[i][j - 1][0];
                        dp[i][j][2] = 1;
                    }
                    if(dp[i - 1][j][1] < dp[i][j - 1][1])
                    {
                        dp[i][j][1] = dp[i - 1][j][1];
                        dp[i][j][3] = 0;
                    }
                    else
                    {
                        dp[i][j][1] = dp[i][j - 1][1];
                        dp[i][j][3] = 1;
                    }
                }
                int tmp = base_arr[i][j];
                while(tmp % 2 == 0)
                {
                    dp[i][j][0] += 1;
                    tmp /= 2;
                }
                tmp = base_arr[i][j];
                while(tmp % 5 == 0)
                {
                    dp[i][j][1] += 1;
                    tmp /= 5;
                }
            }
        }
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][0]);
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][1]);
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][2]);
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        // for (int i = 0; i < n; ++i)
        // {
        //     for (int j = 0; j < n; ++j)
        //     {
        //         printf("%d ", dp[i + 1][j + 1][3]);
        //     }
        //     cout << endl;
        // }
        if(flag == 1)
        {
            printf("1\n");
            for(i = 1; i <= zx; ++i)
            {
                printf("D");
            }
            for(i = zy; j <= n; ++j)
            {
                printf("R");
            }
            printf("\n");
        }
        else
        {
            if(dp[n][n][0] < dp[n][n][1])
            {
                // cout << "adgdf" << endl;
                printf("%d\n", dp[n][n][0]);
                printpath(2, n);
            }
            else
            {
                // cout << "frbgr" << endl;
                printf("%d\n", dp[n][n][1]);
                printpath(3, n);
            }
        }
    }
return 0;
}


//Cf-2B.cpp
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long lovelive;
const int inf = INT_MAX;
const double pai = acos(-1.0);
const double gold = (sqrt(5.0) - 1.0) / 2.0;
int base_arr[1117][1117], dp[1117][1117][4];

void init()
{
    memset(base_arr, 0, sizeof(base_arr));
    memset(dp, 0, sizeof(dp));
return ;
}

void printpath(int kind, int n)
{
    int i = 1, j = 1, k;
    while(i != n || j != n)
    {
        if(dp[i][j][kind] == 0)
        {
            if(j == n)
            {
                printf("D"); i += 1;
            }
            else
            {
                printf("R"); j += 1;
            }
        }
        else if(dp[i][j][kind] == 1)
        {
            if(i == n)
            {
                printf("R"); j += 1;
            }
            else
            {
                printf("D"); i += 1;
            }
        }
        // cout << i << " " << j << endl;
    }
    printf("\n");
return ;
}
int main(int argc, char const *argv[])
{
    // freopen("in.in", "r", stdin);
    int n, i, j, k, flag, zx, zy;
    while(scanf("%d", &n) != EOF)
    {
        init(), flag = 0;
        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                scanf("%d", &base_arr[i][j]);
                if(base_arr[i][j] == 0 && !flag)
                {
                    flag = 1;
                    zx = i, zy = j;
                }
            }
        }

        for(i = 1; i <= n; ++i)
        {
            for(j = 1; j <= n; ++j)
            {
                if(i == 1)
                {
                    dp[i][j][0] = dp[i][j - 1][0];
                    dp[i][j][1] = dp[i][j - 1][1];
                    dp[i][j][2] = dp[i][j][3] = 0;
                }
                else if(j == 1)
                {
                    dp[i][j][0] = dp[i - 1][j][0];
                    dp[i][j][1] = dp[i - 1][j][1];
                    dp[i][j][2] = dp[i][j][3] = 1;
                }
                else
                {
                    if(dp[i - 1][j][0] < dp[i][j - 1][0])
                    {
                        dp[i][j][0] = dp[i - 1][j][0];
                        dp[i][j][2] = 1;
                    }
                    else
                    {
                        dp[i][j][0] = dp[i][j - 1][0];
                        dp[i][j][2] = 0;
                    }
                    if(dp[i - 1][j][1] <= dp[i][j - 1][1])
                    {
                        dp[i][j][1] = dp[i - 1][j][1];
                        dp[i][j][3] = 1;
                    }
                    else
                    {
                        dp[i][j][1] = dp[i][j - 1][1];
                        dp[i][j][3] = 0;
                    }
                }
                int tmp = base_arr[i][j];
                while(tmp % 2 == 0)
                {
                    dp[i][j][0] += 1;
                    tmp /= 2;
                }
                while(tmp % 5 == 0)
                {
                    dp[i][j][1] += 1;
                    tmp /= 5;
                }
            }
        }
        if(flag == 1)
        {
            printf("1\n");
            for(i = 1; i <= zx; ++i)
            {
                printf("D");
            }
            for(i = zy; j <= n; ++j)
            {
                printf("R");
            }
            printf("\n");
        }
        else
        {
            if(dp[n][n][0] < dp[n][n][1])
            {
                // cout << "adgdf" << endl;
                printf("%d\n", dp[n][n][0]);
                printpath(2, n);
            }
            else
            {
                // cout << "frbgr" << endl;
                printf("%d\n", dp[n][n][1]);
                // for(i = 1; i <= n; ++i)
                // {
                //     for(j = 1; j <= n; ++j)
                //     {
                //         printf("%d ", dp[i][j][3]);
                //     }
                //     printf("\n");
                // }
                printpath(3, n);
            }
        }
    }
return 0;
}


#include <bits/stdc++.h>
#include <ext/algorithm>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#ifdef HOME
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#else
#define DB(x)
#endif

#ifndef __GXX_EXPERIMENTAL_CXX0X__
#define foreach(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#endif

typedef long long i64;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;

    vector<vector<pii>> m(n+1,vector<pii>(n+1));
    vector<pii> zeros;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
        {
            int x; cin >> x;

            if(x == 0) zeros.push_back(pii(i,j)), m[i][j] = pii(1,1);
            else
            {
                while(x % 2 == 0) m[i][j].first++, x /= 2;
                while(x % 5 == 0) m[i][j].second++, x /= 5;
            }
        }

    vector<vector<int>> dp2(n+1,vector<int>(n+1)), dp5(n+1,vector<int>(n+1));
    for(int i = 0; i <= n; ++i)
        dp2[i][0] = dp2[0][i] = dp5[i][0] = dp5[0][i] = 1 << 29;
    dp2[0][1] = dp5[1][0] = 0;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
        {
            dp2[i][j] = m[i][j].first + min(dp2[i-1][j],dp2[i][j-1]);
            dp5[i][j] = m[i][j].second + min(dp5[i-1][j],dp5[i][j-1]);
        }

    int best = min(dp2[n][n],dp5[n][n]);

    if(best && !zeros.empty())
    {
        cout << 1 << endl;
        int y = zeros.front().second;
        cout << string(y-1,'R') << string(n-1,'D') << string(n-y,'R') << endl;
    }
    else
    {
        cout << best << endl;
        string ans;

        if(best == dp2[n][n])
            for(int i = n, j = n; i != 1 || j != 1; )
            {
                if(best == m[i][j].first + dp2[i-1][j])
                    ans += 'D', --i;
                else ans += 'R', --j;
                best = dp2[i][j];
            }
        else
            for(int i = n, j = n; i != 1 || j != 1; )
            {
                if(best == m[i][j].second + dp5[i-1][j])
                    ans += 'D', --i;
                else ans += 'R', --j;
                best = dp2[i][j];
            }

        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/algorithm>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#ifdef HOME
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl;
#else
#define DB(x)
#endif

#ifndef __GXX_EXPERIMENTAL_CXX0X__
#define foreach(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#endif

typedef long long i64;
typedef pair<int,int> pii;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;

    vector<vector<pii>> m(n+1,vector<pii>(n+1));
    vector<pii> zeros;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
        {
            int x; cin >> x;

            if(x == 0) zeros.push_back(pii(i,j)), m[i][j] = pii(1,1);
            else
            {
                while(x % 2 == 0) m[i][j].first++, x /= 2;
                while(x % 5 == 0) m[i][j].second++, x /= 5;
            }
        }

    vector<vector<int>> dp2(n+1,vector<int>(n+1)), dp5(n+1,vector<int>(n+1));
    for(int i = 0; i <= n; ++i)
        dp2[i][0] = dp2[0][i] = dp5[i][0] = dp5[0][i] = 1 << 29;
    dp2[0][1] = dp5[1][0] = 0;

    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
        {
            dp2[i][j] = m[i][j].first + min(dp2[i-1][j],dp2[i][j-1]);
            dp5[i][j] = m[i][j].second + min(dp5[i-1][j],dp5[i][j-1]);
        }

    int best = min(dp2[n][n],dp5[n][n]);

    if(best && !zeros.empty())
    {
        cout << 1 << endl;
        int y = zeros.front().second;
        cout << string(y-1,'R') << string(n-1,'D') << string(n-y,'R') << endl;
    }
    else
    {
        cout << best << endl;
        string ans;

        if(best == dp2[n][n])
            for(int i = n, j = n; i != 1 || j != 1; )
            {
                if(best == m[i][j].first + dp2[i-1][j])
                    ans += 'D', --i;
                else ans += 'R', --j;
                best = dp2[i][j];
            }
        else
            for(int i = n, j = n; i != 1 || j != 1; )
            {
                if(best == m[i][j].second + dp5[i-1][j])
                    ans += 'D', --i;
                else ans += 'R', --j;
                best = dp5[i][j];
            }

        reverse(ans.begin(), ans.end());
        cout << ans << endl;
    }

    return 0;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdlib>

using namespace ::std;

typedef vector<bool> Path;
ostream &operator<< (ostream &os, Path &p) {
	for (auto direction : p)
		os << "DR"[direction];
	return os;
}

struct Cell {
	unsigned n, twos, fives;
	Cell (int _n) : n(_n), twos(0), fives(0) {
//		cerr << "Cell(" << _n << ")" << endl;
		while (_n && !(_n & 1))
			++twos, _n /= 2;
		while (_n & !(_n % 5))
			++fives, _n /= 5;
//		cerr << "Cell { " << n << ", " << twos << ", " << fives << "}" << endl;
	}
};

typedef vector<Cell> Row;
typedef vector<Row> Grid;

struct SearchState { unsigned x, y, twos, fives; };
ostream &operator<< (ostream &os, const SearchState &ss) {
	return os << "{ " << ss.x << ", " << ss.y << ", " << ss.twos << ", " << ss.fives << " }";
}

struct State {
	unsigned size, lwm;
	Grid cells;
	Path path, bestPath;
	State () : size(0), lwm(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size);
		for (unsigned value, r = 0; r < size; ++r) {
			cells.emplace_back();
			Row &row = cells.back();
			row.reserve(size);
			for (unsigned c = 0; c < size; ++c) {
				is >> value, row.emplace_back(value);
			}
		}
		return is;
	}
	void Search (SearchState s, bool direction) {
		cerr << "state = " << s << ", direction = " << "DR"[direction] << endl;
		if ( ( direction ? ++s.x : ++s.y ) >= size )
			return;
		path.push_back(direction);
		Search (s);
		path.pop_back();
	}
	void Search (SearchState &s) {
		Cell &cell = cells[s.x][s.y];
		unsigned tens = min( (s.twos += cell.twos), (s.fives += cell.fives) );
		cerr << "state = " << s << ", tens = " << tens << ", path = " << path << endl;
		if ( tens >= lwm )
			return;
		else if ( s.x == size - 1 && s.x == s.y ) {
			lwm = tens;
			bestPath = path;
			cerr << "lwm = " << lwm << ", path = " << path << endl;
		} else {
			bool acrossFirst = s.y >= s.x;
			Search(s, acrossFirst);
			Search(s, !acrossFirst);
		}
	}
	void Search () {
		lwm = numeric_limits<unsigned>::max();
		bestPath.clear();
		path.clear();
		path.reserve( 2 * (size - 1) );
		SearchState state { 0, 0, 0, 0 };
		Search(state);
		cout << lwm << endl << bestPath << endl;
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }

int
main ()
{
	// apparently this may speed it up
	ios_base::sync_with_stdio(false);

	State state;
	cin >> state;
	state.Search();

	return EXIT_SUCCESS;
}


#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <memory>
#include <cstdlib>

using namespace ::std;

unsigned uMax = numeric_limits<unsigned>::max();

struct Factor {
	unsigned best;
	bool direction;
	inline Factor ( unsigned &value, unsigned factor, bool __d = false )
		: best(0), direction(__d)
	{
		while (value && !(value % factor))
			++best, value /= factor;
	}
	void BestFrom (const Factor &other, bool fromAbove) {
		best += other.best;
		direction = fromAbove;
	}
	void BestFrom (const Factor &left, const Factor &above) {
		bool fromAbove = above.best < left.best;
		BestFrom (fromAbove ? above : left, fromAbove);
	}
	ostream &Print(ostream &os) const {
		return os << "{ " << best << ", " << "DR"[direction] << " }";
	}
};
inline ostream &operator<< (ostream &os, const Factor &f) { return f.Print(os); }
template<unsigned N> struct FactorMaker : public Factor {
	FactorMaker (unsigned &value) : Factor(value, N, false) { }
};

struct State {
	unsigned size;
	vector<unsigned> cells;
	vector<Factor> twos, fives;
	State () : size(0) { }
	istream &Read (istream &is) {
		is >> size;
		cells.reserve(size * size);
		for (unsigned value, r = 0; r < size; ++r) {
			for (unsigned c = 0; c < size; ++c) {
				is >> value;
				cells.emplace_back(value);
				twos.emplace_back( FactorMaker<2> { value } );
				fives.emplace_back( FactorMaker<5> { value } );
			}
		}
		Fill (twos);
		Fill (fives);
		return is;
	}
	void Fill (vector<Factor> &factors) {
		Factor *fi = factors.data(), *prevRow = fi, *prevCol = prevRow;
		// top row, resetting the iterator ...
		for ( unsigned c = 1 ; c < size; ++c )
			(++fi)->BestFrom(*prevCol++, false);
		for ( unsigned r = 1; r < size; ++r ) {
			(++fi)->BestFrom(*prevRow++, true);
			for ( unsigned c = 0; ++c < size; )
				(++fi)->BestFrom(*++prevCol, *prevRow++);
		}
	}
	ostream &PrintResult (ostream &os, vector<Factor> &factors) {
		string s;
		auto fi = factors.end() - 1;
		while (fi != factors.begin()) {
			s += "RD"[fi->direction];
			fi -= fi->direction ? size : 1;
		}
		reverse (s.begin(), s.end());
		return os << s;
	}
	ostream &Write (ostream &os) {
		return PrintResult (os, twos.back().best < fives.back().best ? twos : fives);
	}
};
inline istream &operator>> (istream &is, State &s) { return s.Read(is); }
inline ostream &operator<< (ostream &os, State &s) { return s.Write(os); }

int
main ()
{
	// apparently this may speed it up
	ios::sync_with_stdio(false);

	State state;
	cin >> state;
	cout << state;

	return EXIT_SUCCESS;
}