N = int(input())
As = list(map(int,input().split()))
Q = int(input())

lst = [0] * (10**5)
for A in As:
    lst[A] += 1

outs = []

for i in range(0,Q):
    B, C = map(int,input().split())
    lst[C] += lst[B]
    lst[B] = 0
    outs.append(sum([i*j for i,j in enumerate(lst)]))

for out in outs:
    print(out)