import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())))
q=int(input())
b=[]
c=[]
for i in range(q):
    b1,c1=np.array(list(map(int,input().split())))
    b.append(b1)
    c.append(c1)

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