import collections as c

n = int(input())

a = list(map(int,input().split()))

q = int(input())

cnt = [0]*100000

for i in range(100000):
    cnt[i] = a.count(i+1)

for i in range(q):
    b,c = map(int,input().split())
    x = cnt[b-1]
    cnt[b-1] = 0
    cnt[c-1] = cnt[c-1] + x
    ans = 0
    for s in range(100000):
        ans += (s+1)*cnt[s]
        
    print(ans)