import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
q=int(input())
b=[[],[]]

for i in range(q):
    b1,c1=np.array(list(map(int,input().split())))
    b[0].append(b1)
    b[1].append(c1)

for i in range(q):
    for j,k in enumerate(a):
        if b[0][i]==k:
            a[j]=b[1][i]
    sum=np.sum(a)
    print(sum)
