N=int(input())
A=list(map(int,input().split()))
S=sum(A)
Q=int(input())
for i in range(Q):
    B,C=map(int,input().split())
    S=S+(C-B)*A.count(B)
    A = [C if i ==B  else i for i in A]
    print(S)
