n = int(input())
a = list(map(int, input().split()))
cnt = [0]*(10**5)
for i in range(0,10*5):
    cnt[i] = a.count(i+1)
s = sum(a)
q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    s += (c-b)*cnt[b-1]
    cnt[c-1]+=cnt[b-1]
    cnt[b-1]=0
    print(s)