def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[]
for i in range(Q):
    BC.append(list(map(int,input().split())))
for i in BC:
    indexlist=my_index_multi(A,i[0])
    for j in indexlist:
        A[j]=i[1]
    print(sum(A))