import sys
import numpy as np
from numba import njit



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


@njit('(i8[:], i8, i8[:])',cache=True)
def loop(a,q,bc):
    for i in range(q):
        a = np.where(a == bc[i*2], bc[i*2+1], a)
        print(np.sum(a))

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