#from collections import defaultdict

n = int(input())
cnt =[0]*10**5

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

for i in l:
    cnt[i] += 1
    
sums = sum(l)
    
m = int(input())

for i in range(m):
    a,b = map(int, input().split())
    
    diff = (b-a)*cnt[a]
    sums += diff
    print(sums)
    
    cnt[b] += cnt[a]
    cnt[a] = 0