import collections
import numpy as np

n=int(input())
A = list(map(int,input().split()))
Q=int(input())
B=[0]*Q
C=[0]*Q
for i in range(Q):
  B[i], C[i]=map(int,input().split())
#print(A,B,C)

c = collections.Counter(A)
values, counts = map(np.array,zip(*c.most_common()))
#print(values,counts)

for i in range(Q):
  values=np.where(values==B[i],C[i],values)
  print(np.dot(values,counts))
  
  