n = int(input())
a = list(map(int, input().split()))
q = int(input())

b, c = [0] * q, [0] * q
for i in range(q):
    b[i], c[i] = map(int, input().split())

a.sort()

for i in range(q):
    if b[i] in a:
        s = a.index(b[i])
        while s < n and a[s] == b[i]:
            a[s] = c[i]
            s += 1
    print(sum(a))