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

B=[]
C=[]
for i in range(Q):
    b,c=map(int,input().split())
    B.append(b)
    C.append(c)

S=[]
for i in range(Q):
    num=A.count(B[i])
    for j in range(num):
        index_A=A.index(B[i])
        A[index_A]=C[i]
    S.append(sum(A))

print(S)