N =int(input())
A_n =list(map(int,input().split()))
Q =int(input())
B_n ,C_n=[],[]
for i in range(Q):
    B,C =map(int,input().split())
    B_n.append(B)
    C_n.append(C)

sum0 =sum(A_n)
for i in range(Q):
    count =A_n.count(B_n[i])
    sum0 += (C_n[i]-B_n[i])*count
    A_n  =list(filter(lambda x: x != B_n[i] ,A_n))
    A_n.extend([C_n[i] for j in range(count)])
    print(sum0)