n=int(input())
arr=list(map(int,input().split()))
q=int(input())
for i in range(q):
    x,y=(map(int,input().split()))
    while(1):
        if x not in arr:
            break
        else:
            po=arr.index(x)
            arr[po]=y
    print(sum(arr))