n=int(input())
#a,b=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
q=int(input())
import collections
dic=collections.Counter(al)
total=sum(al)
for i in range(q):
    b,c=map(int,input().split())
    b_num=dic[b]
    total=total+b_num*(c-b)
    print(total)
    dic[c]=dic.get(c,0)+b_num

