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

for i in range(q):
  sum = 0
  for j in range(n):
    if bc[i][0] == a[j]:
      sum += bc[i][1]
      a[j] = bc[i][1]
    else:
      sum += a[j]
  print(sum)