def calc(b, c):
  _sum = 0
  for i in range(n):
    a[i] = c if a[i] == b else a[i]
    _sum += a[i]
  return _sum

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
  b, c = map(int, input().split())
  print (calc(b, c))