n = int(input())
la = list(map(int,input().split()))
q = int(input())
lb = [0]*q
lc = [0]*q
ld = [0]*q
for i in range(q):
  lb[i],lc[i] = map(int,input().split())
  ld[i] = lc[i] - lb[i]
sum = sum(la)
max = max(la)
la2 = [0]*(10**5)
for i in range(max):
  la2[i] = la.count(i+1)
for i in range(q):
  m = la2[lb[i]-1]
  sum = sum + ld[i]*m
  la2[lc[i]-1]=la2[lc[i]-1]+m
  print(sum)