n=int(input())
p=list(map(int,input().split()))
q=int(input())
     
for i in range(q):
        b,c=map(int,input().split())
        k=p.count(b)
        
        for j in range(0,len(p)):
            if (p[j]==b) and (k>0):
                p[j]=c
                k=k-1
            elif k==0:
              break
            
        print(sum(p))