import time
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

num = {}
for i in A:
    if i in num:
        num[i] += 1
    else:
        num[i] = 1
for i in range(Q):
    p, n = BC[i][0], BC[i][1]
    if p in num:
        if n in num:
            num[n] += num[p]
        else:
            num[n] = num[p]
        num[p] = 0
    ans = 0
    for k, v in num.items(): ans += k * v
    print(ans)