#d
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]
old_sum = sum(a)
for i in range(q):
    l = a.count(b[i])
    for j in [z for z, x in enumerate(a) if x == b[i]]:
        a[j]=c[i]
    old_sum = old_sum + l*(c[i]-b[i])
    print(old_sum)