n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
    j = 0
    while bc[i][0] >= a[j]:
        if a[j] == bc[i][0]:
            a[j] = bc[i][1]
        j += 1
        if n == j:
            break
    a = sorted(a)
    print(sum(a))