n = int(input())
a = list(map(int, input().split()))
q = int(input())

def list1(n):
  if n == b:
    return c
  else:
    return n
  
for i in range(q):
  b, c = map(int, input().split())
  a = list(map(list1, a))
  print(sum(a))

