n=int(input())
l=list(map(int,input().split()))
o=int(input())

for i in range(o):
    summ=0
    a,b=map(int,input().split())
    for x in range(n):
        if l[x]==a:
            l[x]=b 
        
        summ+=l[x]
    print(summ)    
            