import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
q = int(input())
S = []

for i in range(q):
    b, c = [int(i) for i in input().split()]
    a = np.where(a == b, c, a)
    S.append(np.sum(a))
    
for i in range(q):
    print(S[i])