import sys
input = sys.stdin.readline 
N=int(input())
L=list(map(int,input().split()))
Q=int(input())
for i in range(Q):
  a,b=map(int,input().split())
  L=[i if i!=a else b for i in L]
  print(sum(L))