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