dig = {}
dig[1] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
dig[3] = [0, 7, 4, 1, 8, 5, 2, 9, 6, 3]
dig[7] = [0, 3, 6, 9, 2, 5, 8, 1, 4, 7]
dig[9] = [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]
# dig[x][y] gives the digit z such that x * z = p, where p has last digit y
def solve(n, x):
x0 = x % 10
y = dig[x0][1]
pow10 = 10
for i in range(1, n):
curdig = ((x * y) // pow10) % 10 # current ith digit of the product
reqdig = (10 - curdig) % 10 # the digit we want to add to the current digit to get 0
ydig = dig[x0][reqdig] # the next digit of y we need to get the required digit
y = ydig * pow10 + y # update y
pow10 *= 10
return y
for t in range(int(input())):
n, x = map(int, input().split())
print(solve(n, x))
ZGlnID0ge30KZGlnWzFdID0gWzAsIDEsIDIsIDMsIDQsIDUsIDYsIDcsIDgsIDldCmRpZ1szXSA9IFswLCA3LCA0LCAxLCA4LCA1LCAyLCA5LCA2LCAzXQpkaWdbN10gPSBbMCwgMywgNiwgOSwgMiwgNSwgOCwgMSwgNCwgN10KZGlnWzldID0gWzAsIDksIDgsIDcsIDYsIDUsIDQsIDMsIDIsIDFdCgojIGRpZ1t4XVt5XSBnaXZlcyB0aGUgZGlnaXQgeiBzdWNoIHRoYXQgeCAqIHogPSBwLCB3aGVyZSBwIGhhcyBsYXN0IGRpZ2l0IHkKCmRlZiBzb2x2ZShuLCB4KToKCXgwID0geCAlIDEwCgl5ID0gZGlnW3gwXVsxXQoJcG93MTAgPSAxMAoJZm9yIGkgaW4gcmFuZ2UoMSwgbik6CgkJY3VyZGlnID0gKCh4ICogeSkgLy8gcG93MTApICUgMTAgICMgY3VycmVudCBpdGggZGlnaXQgb2YgdGhlIHByb2R1Y3QKCQlyZXFkaWcgPSAoMTAgLSBjdXJkaWcpICUgMTAgICAgICAgIyB0aGUgZGlnaXQgd2Ugd2FudCB0byBhZGQgdG8gdGhlIGN1cnJlbnQgZGlnaXQgdG8gZ2V0IDAKCQl5ZGlnID0gZGlnW3gwXVtyZXFkaWddICAgICAgICAgICAgIyB0aGUgbmV4dCBkaWdpdCBvZiB5IHdlIG5lZWQgdG8gZ2V0IHRoZSByZXF1aXJlZCBkaWdpdAoJCXkgPSB5ZGlnICogcG93MTAgKyB5ICAgICAgICAgICAgICAjIHVwZGF0ZSB5CgkJcG93MTAgKj0gMTAKCXJldHVybiB5CgkJCmZvciB0IGluIHJhbmdlKGludChpbnB1dCgpKSk6CgluLCB4ID0gbWFwKGludCwgaW5wdXQoKS5zcGxpdCgpKQoJcHJpbnQoc29sdmUobiwgeCkp