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 = {}
for a_i in a:
    if not a_i in res:
        res[a_i] = 0
    res[a_i] += 1

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

    ans = 0
    for key, val in res.items():
        ans += key * val
    print(ans)
