n=int(input())
a=list(map(int,input().split()))
q=int(input())

summ=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    b_num=a.count(b)
    a=[c if i==b else i for i in a]
    summ +=(c-b)*b_num
    print(summ)