n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = []
ans = []
for i in range(q):
    bc.append(list(map(int,input().split())))
    while bc[i][0] in a:
        a[a.index(bc[i][0])] = bc[i][1]
    ans.append(sum(a))
for i in range(len(ans)):
    print(ans[i])