import numpy as np

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0 for _ in range(q)]
c = [0 for _ in range(q)]
for i in range(q):
    b[i], c[i] = map(int, input().split())

a = np.array(a)
for num, rep in zip(b, c):
    if num in set(a):
        a = np.where(a == num, rep, a)
        print(sum(a))
    else:
        print(sum(a))
        continue