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