import numpy as np

n = int(input())

a = list(map(int, input().split()))
l = [0 for i in range(100010)]

q = int(input())

s = np.sum(a)

for ae in a:
    l[ae] += 1

ans = []

for i in range(q):
    b, c = map(int, input().split())

    m_num = l[b]
    l[b] = 0
    m_s = m_num*b

    p_s = m_num*c
    l[c] += m_num

    s = s - m_s + p_s

    ans.append(s)

for i in range(q):
    print(ans[i])
