n = int(input())
p = list(map(int, input().split()))
q = int(input())

s = sum(p)
result = ""

for r in range(0, q, 1):
  e = list(map(int, input().split()))
  for i in range(0, n, 1):
     if(p[i] == e[0]):
        p[i] = e[1]
        s -= (e[0] - e[1])
  result += str(s)+"\n"

print(result.rstrip("\n"))