from sys import stdin

f = eval(stdin.readline())
g = eval(stdin.readline())
h = conv_dig(f, g)
for line in stdin:
    if line.startswith("==="):
        f = eval(stdin.readline())
        g = eval(stdin.readline())
        h = conv_dig(f, g)
    else:
        print(line.strip(), h(int(line)))
