N=int(input())
A=[int(x) for x in input().split()]
Q=int(input())
for i in range(Q):
  total=0
  B,C=map(int,input().split())
  if B in A:
    A.remove(B)
    B=C
    A.append(C)
    for j in range(len(A)):
      total+=A[j]
    print(total)  