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

q = int(input())
bb = []
cc = []

for i in range(q):
  b, c = map(int, input().split())
  bb.append(b)
  cc.append(c)
  
for i in range(q):
  sum = 0
  for j in range(n):
    if a[j] == bb[i]:
      a[j] = cc[i]
    sum = sum + a[j]
  print(sum)