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