N = int(input())
List = list(map(int,input().split()))
Q = int(input())

S = sum(List)

arr = [0 for i in range(10**5+1)]

for i in range(N):
  a = List[i]
  arr[a] += 1
  
for i in range(Q):
  a,b = map(int,input().split())
  aa = arr[a]
  arr[b] += aa
  S += int ( (b-a) * aa )
  print(int(S))