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

q = int(input())

s = 0
result = []

r = 1
while r <= q:
  e = list(map(int, input().split()))
  i = 0
  while i < n:
     if(p[i] == e[0]):
        p[i] = e[1]
     s = sum(p)
     i += 1

  r += 1
  result.append(str(s))


s_n = '\n'.join(result)
print(s_n)