N = int(input())
num_list = num_list = [i for i in map(int,input().split())]

x = int(input())
num_new = []
for i in range(x):
  b, p = map(int, input().split())
  for j in num_list:
    if j == b:
      j = p
      num_new.append(j)
    else:
      num_new.append(j)
    print(sum(num_new[-N:]))
    
