import numpy as np
N = int(input())
A = np.array((list(map(int, input().split()))))
Q = int(input())
BL = []
CL = []
for _ in range(Q):
    B, C = map(int, input().split())
    BL.append(B)
    CL.append(C)

for i in range(Q):
    A = np.where(A == int(BL[i]), int(CL[i]), A)
    print(sum(A))