if __name__ == "__main__":
  N = int(input())
  A = [int(x) for x in input().split()]
  Q = int(input())
  for i in range(Q):
    B, C = [int(x) for x in input().split()]
    A = [x if x!=B else C for x in A]
    print(sum(A))