n = int(input())
a = input().split()
a_int = [int(x) for x in a]
a_sum = sum(a_int)
a_num = []
for i in range(100001):
    a_num.append(a_int.count(i))

q = int(input())
for i in range(q):
    bc = input().split()
    b = int(bc[0])
    c = int(bc[1])
    n = a_num[b]

    a_sum += (c - b) * n
    print(a_sum)

    a_num[b] = 0
    a_num[c] += n