import numpy as np
N = int(input())
A = map(int, input().split())
a = np.array(A)

Q = int(input())
for i in range(Q):
    B,C = map(int, input().split())
    a = np.where(a == B, C)
    print(sum(a))