n = int(input())
a = list(map(int, input().split()))
q = int(input())
sums = 0

for i in range(q):
  sums = 0
  b,c = map(int, input().split())
  for j in range((len(a))):
    if a[j] == b:
      a[j] = c
    sums += a[j]
    
  print(sums)