n=int(input())
list_a=list(map(int,input().split()))
k=int(input())
for i in range(k):
  a,b=map(int,input().split())
  for k in range(n):
    if list_a[k]==a:
      list_a[k]=b
    else:
      continue
  print(sum(list_a))