#!/usr/bin/env python3

n = int(input())
numbers = input().split(" ")
a = [int(x) for x in numbers]
q = int(input())

r = []


for i in range(q):

  numbers = input().split(" ")
  b = int(numbers[0])
  c = int(numbers[1])
  s = 0

  # a.sort()
  for i in range(n):
    if a[i] == b:
      a[i] = c
    s += a[i]
  r.append(s)

for x in r:
  print(x)



