N,a,q,*bc,=open(0).read().rstrip().split('\n')
N=int(N)
A=[int(s) for s in a.split()]
Q=int(q)
BC=[list(map(int,s.split())) for s in bc]
S=[0]*Q
for i in range(Q):
    for j in range(N):
        if A[j]==BC[i][0]:
            A[j]=BC[i][1]
    S[i]=sum(A)
for k in S:
    print(k)