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(list,zip(*c.most_common()))
#print(values,counts)

for i in range(Q):
  #print(values,counts)
  if B[i] in values:
    idx = values.index(B[i])
  else:
    print(np.dot(np.array(values),np.array(counts)))
    continue
  values.pop(idx)
  num = counts.pop(idx)
  if C[i] in values:
    counts[values.index(C[i])]+=num
  else:
    values.append(C[i])
    counts.append(num)
  print(np.dot(np.array(values),np.array(counts)))
