n = int(input())
A = list(map(int, input().split()))
q = int(input())
BC = [list(map(int, input().split())) for i in range(q)]

list=[0]*100000
sum=sum(A)
for i in A:
    list[i]+=1

for bc in BC:
    x=list[bc[0]]
    sum+=(bc[1]-bc[0])*x
    print(sum)
    list[bc[0]]-=x
    list[bc[1]]+=x