N = int(input())
A = list(map(int,input().split()))
Q = int(input())
S = [list(map(int, input().split())) for l in range(Q)]

l = [0] * 10**5
s = set()
for i in range(N) :
    l[A[i]]+=1
    s.add(A[i])
for i in range(Q):
    s0 = S[i][0]
    s1 = S[i][1]
    l[s1] += l[s0]
    try:
        s.remove(s0)
        s.add(s1)
    except :
        pass
    l[s0] = 0
    tot = 0
    for j in s:
        tot += j * l[j]
    print(tot)