#d
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())
ans=sum(A)
for i in range(Q):
    P=A.count(B[i])
    for j in range(P):
        A[A.index(B[i])]=C[i]
    ans=ans+P*(C[i]-B[i])
    print(ans)