from collections import defaultdict

d = defaultdict(int)

n = int(input())
a = [int(i) for i in input().split(" ")]
q = int(input())

operations = []

for i in range(q):
    temp = input().split(" ")
    operations.append((int(temp[0]), int(temp[1])))


# n = 5
# a = [1, 2, 3, 4, 5]
# q = 3

# operations = [
#     (1, 2),
#     (2, 3),
#     (3, 4)
# ]

for hoge in a:
    d[hoge] += 1


for op in operations:
    target, goto = op

    d[goto] += d[target]

    try:
        del d[target]
        sum = 0
        for key, value in d.items():
            sum += key * value

        print(sum)

    except:
        sum = 0
        for key, value in d.items():
            sum += key * value

        print(sum)     


