n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = list(list(map(int, input().split())) for _ in range(q))
for i in range(q):
    for m, j in enumerate(a):
        if j == b[i][0]:
            a[m] = b[i][1]
    print(sum(a))