n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    b_i, c_i = map(int, input().split())
    b.append(b_i)
    c.append(c_i)

res = [0 for _ in range(10 ** 5 + 1)]
for a_i in a:
    res[a_i] += 1

for b_i, c_i in zip(b, c):
    num = res[b_i]
    res[b_i] = 0
    res[c_i] += num

    ans = 0
    for i in range(len(res)):
        ans += i * res[i]
    print(ans)
