n = int(input())

a = list(map(int, input().split()))
q = int(input())
s = []
S = sum(a)
def find(b, a): #配列aからbを探し出す　
  counter = 0
  for i in range(len(a)):
    if a[i] == b:
      counter += 1
  return counter 
for i in range(q):
  b, c = map(int,input().split())
  count = find(b,a)
  S += count * (c - b)
  print(S)