import numpy as np
n = int(input())
a = list(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, a)
    print(np.sum(a))