n=int(input())
a = list(input().split())
a = [int(i) for i in a]
q=int(input())
#bc=[list(map(int,input().split())) for i in range(q)]

for _ in range(q):
  bi,ci=map(int,input().split())
  a=[ci if bi==a[i] else a[i] for i in range(n)]
  #print(a)
  print(sum(a))
  