#d
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())
D = [0] * (10**5)
ans=sum(A)
for i in A:
    D[i]+=1
for x in range(Q):
    D[C[x]]+=D[B[x]]
    tmp=D[B[x]]
    ans=ans+tmp*(C[x]-B[x])
    print(ans)
    D[B[x]]=0