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