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

for i in range(q):
    a.sort()
    count = 0 
    for j in range(n):
        if b[i]  == a[j]:
            a[j] = c[i]
            count = 1
        else:
            if count == 1:
                break
    print(sum(a))
