import sys
import numpy as np

readline = sys.stdin.readline
read = sys.stdin.read

n = int(readline())
a = np.array(readline().split(), dtype=np.int64)
q = int(readline())
bc = np.array(read().split(), dtype=np.int64)

for i in range(q):
    a = np.where(a == bc[i*2], bc[i*2+1], a)
    print(np.sum(a))
