from collections import Counter

# input
N = int(input())
A = Counter(list(map(int, input().split())))

Q = int(input())
BC = [tuple(map(int, input().split())) for q in range(Q)]

# check
for before, after in BC:
    if before in A.keys():
        cnt = A[before]
        del A[before]
        add = Counter({after: cnt})
        A = A + add
    print(sum(list(A.elements())))