N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
C=[]
for i in range(Q):
    b,c=input().split()
    B.append(int(b))
    C.append(int(c))
S=0
D={}
for i in range(1,10**5+1):
    k=A.count(i)
    D[i]=k
    S=S+i*k
for i in range(Q):
    n=D[B[i]]
    S=S+n*(C[i]-B[i])
    D[C[i]]=D[C[i]]+n
    print(S)