def main():
  n = int(input())
  a = list(map(int,input().split()))
  q = int(input())
  Rangeq = list(range(q))
  xy = [map(int, input().split()) for _ in Rangeq]
  x, y = [list(i) for i in zip(*xy)]
  for j in Rangeq:
    a = [y[j] if i==x[j] else i for i in a]
    print(sum(a))
main()