# -*- coding: utf-8 -*-
import numpy as np

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

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

a = np.array(a)

for i in range(q):
    a = np.where(a == b[i], c[i], a)
    print(np.sum(a))
