n = int(input())
a = list(map(int, input().split()))
s = sum(a)
q = int(input())
b = []
c = []
# diff = []
for i in range(q):
    _ = list(map(int, input().split()))
    c.append(_[1])
    b.append(_[0])

for i in range(q):
    for j in range(n):
        if b[i] == a[j]:
            a[j] = c[i]
    print(sum(a))
