import sys
import numpy as np
from numba import jit
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# --------------------------
@jit('i8(i8[:])')
def change(arr):
    b, c = map(int, input().split())
    arr = np.where(arr == b, c, arr)
    print(np.sum(arr))

    return arr


# -------------------------
n = int(input())
a = list(map(int, input().split()))
'''
aa = ''.join(a)
aaa = str(aa)
#print(type(aa))
# print(a)
'''
aa = np.array(a)
q = int(input())


for i in range(q):
    aa = change(aa)

    # print(aa)
    #aaa.replace(str(b), str(c))
    # print(aaa)

#ab = map(int, aa)
# print(np.sum(aa))
