n=int(input())
l=list(map(int,input().split()))
t=int(input())
#s=sum(l)
for i in range(t):
    b,c=map(int,input().split())
    p=l.count(b)
    co=0
    #print(p)
    for x,y in enumerate(l):
        if(y==b):
            l[x]=c
            co+=1
        if(co==p):
            co=0
            break
        
    
    
    
    print(sum(l))
    
    
