n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(list(map(int, input().split())))

for i in range(q):
    a = [bc[i][1] if bc[i][0] == j else j for j in a]
    print(sum(a))

