n =int(input())
a = list(map(int,input().split()))
A =set(a)
q =int(input())
for _ in range (q):
  b, q = map(int,input().split())
  if b in A:
    a = [q if _ == b else _ for _ in a]
    A =set(a)
  print(sum(a))