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

S=[]
S.append(sum(A))

for i in range(Q):
    b,c=map(int,input().split())
    num=A.count(b)
    for j in range(num):
        index_A=A.index(b)
        A[index_A]=c
   
    S.append(S[i]+num*(c-b))

for i in range(1,1+Q):
    print(S[i])