N = int(input())
A = list(map(int,input().split()))
dA = {}
for a in A:
  dA[a] = 0
for a in A:
  dA[a] += 1
Q = int(input())
for q in range(Q):
  B,C = map(int,input().split())
  sA = set(dA)
  if B in sA:

  s = 0
  for a in dA:
    s += a * dA[a]
  print(s)
  