n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
s=0
for i in range(n):
    s+=a[i]
for i in range(q):
    res=a.count(bc[i][0])
    s+=(bc[i][1]-bc[i][0])*res
    a=[bc[i][1] if ai==bc[i][0] else ai for ai in a]
    print(s)
