import numpy as np

N = int(input())
A_temp = list(map(int,input().split()))
A = np.array(A_temp)
Q = int(input())
result = []

for q in range(Q):
    B,C = map(int,input().split())
    A = np.where(A==B,C,A)
    result.append(np.sum(A))
[print(i) for i in result]