N=int(input())
A=list(map(int,input().split()))
Q=int(input())

B=[]
C=[]
S=[]
for i in range(Q):
    b,c=map(int,input().split())
    num=A.count(b)
    if num!=0:
        for j in range(num):
            index_A=A.index(b)
            A[index_A]=c
   
    S.append(sum(A))

print(S)