n = int(input())
 
a = list(map(int, input().split()))
q = int(input())
s = []
S = sum(a)
def find(b, a, c): #配列aからbを探し出して,bをcに変換
  counter = 0
  for i in range(len(a)):
    if a[i] == b:
      a[i] = c
  return a
for i in range(q):
  b, c = map(int,input().split())
  a = find(b,a, c)
  print(sum(a))