from collections import Counter
N=int(input())
A=list(map(int,input().split()))
s=sum(A)
Q=int(input())
cnt=Counter(A)
for _ in range(Q):
    b,c=map(int,input().split())
    if b in cnt:
        t=cnt[b]
        if t>0:
            s-=t*b
            s+=t*c
            print(s)
            if c in cnt:
                cnt[c]+=t
                cnt[b]=0
            else:
                cnt[c]=t
        else:
            print(s)
    else:
        print(s)