n = int(input())
a = list(map(int,input().split()))
q = int(input())
a_list = [[i, 0] for i in range(10**5 +1)]

for elem in a:
    a_list[elem][1] += 1

for i in range(q):
    b, c = map(int,(input().split()))
    a_list[c][1] += a_list[b][1]
    a_list[b][1] = 0
    ans = 0
    for j in a_list:
        ans += j[0] * j[1]
    print(ans)