N = int(input())
p = input().split()
p_int = [int(n) for n in p]
Q = int(input())
for i in range(Q):
  sum = 0
  B, C = map(int, input().split())
  for n in range(N):
    if p_int[n] == B:
      p_int[n] = C
    sum += p_int[n]
  print(sum)