import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
for x in range(q):
    b.append(list(map(int, input().split())))

hikaku = 0
a_wa = sum(a)

for i in range(q):
    cou = collections.Counter(a)

    a_wa += cou[b[i][0]] * b[i][1] - cou[b[i][0]] * b[i][0]
    for l in range(cou[b[i][0]]):
        a.remove(b[i][0])
        a.append(b[i][1])

    print(a_wa)