import numpy as np

def main():
  n = int(input())
  a = np.array(list(map(int, input().split())))
  q = int(input())
  
  for _ in range(q):
    b, c = map(int, input().split())
    a = [c if i == b else i for i in a]
    print(sum(a))
  
main()