from sys import stdin
N = int(stdin.readline().rstrip())
list = [int(x) for x in stdin.readline().rstrip().split()]
Q = int(stdin.readline().rstrip())
#print(list)
for i in range(Q):
  s, t = [int(x) for x in stdin.readline().rstrip().split()]
  sum1 = 0
  for j in range(len(list)):
    if list[j] == s:
      list[j] = t
    elif list[j] > s:
      break;
  sum1 = sum(list)
  list.sort()
  print(sum1)