n=int(input())
a=list(map(int,input().split()))
q=int(input())
k=[]

while(q!=0):
    b,c=map(int,input().split())
    s=0
    for i in range(n):
        if(a[i]==b):
            a[i]=c
            s+=c
        else:
            s+=a[i]
    k.append(s)
    q-=1
for i in range(len(k)):
    print(k[i],end="\n")
    
    
    
    



