import bisect
import numpy as np
n = int(input())
a = list(map(int, input().split()))
q = int(input())
a.sort()
A = list(set(a))
CA = [0]*len(A)
for i,x in enumerate(A):
  l = bisect.bisect_left(a,x)
  r = bisect.bisect_right(a,x)
  CA[i] = r-l

def trans(A,b,c):
  for i,x in enumerate(A):
    if x == b:
      A[i] = c
  return A

A = np.array(A)
CA = np.array(CA) 
for i in range(q):
  b,c = list(map(int, input().split()))
  A = trans(A,b,c)
  ans = A * CA
  print(sum(ans))