import math as mt
import collections as cc
I=lambda:list(map(int,input().split()))
n,=I()
l=I()
f=cc.Counter(l)
s=sum(l)
for i in range(int(input())):
    x,y=I()
    s-=x*(f[x])
    s+=f[x]*y
    f[y]=f[x]
    f[x]=0
    print(s)
    
    
    