import numpy as np

def sum(n, a):
  ans = 0
  n = int(n)
  for num in range(n):
    ans += int(a[num])
  print(ans)

n = input()
n = int(n)
a = [e for e in input().split()]
q = input()
q = int(q)

for num in range(q):
  b1,b2 = input().split()
  ans = 0
  for num in range(n):
    if a[num] == b1:
      ans += int(b2)
    else:
      ans += int(a[num])
  print(ans)