t = int(input())
arr = list(map(int, input().split()))
Sum = sum(arr)
t1 = int(input())
ans = []
for i in range(t1):
  b,c = list(map(int, input().split()))
  arr = [c if x==b else x for x in arr]
  print(sum(arr))
