n=int(input())
l=list(map(int,input().split()))
k=int(input())
for i in range(k):
    k=0
    sum=0
    a,b=map(int,input().split())
    for j in l:
        if a==j:
            l[k]=b
        sum+=l[k]
        k+=1
    print(sum)
        
