n=int(input())
a=list(map(int,input().split()[:n]))
q=int(input())
b=[]
c=[]
for i in range(q):
    l= list(map(int,input().split()))
    b.append(l[0])
    c.append(l[1])    
res_sum=[]
for i in range(q):
    for j in range(len(a)):
        if a[j]==b[i]:
            a[j]=c[i]
    res_sum.append(sum(a))
for i in res_sum:
    print(i)