import numpy as np
n=int(input())
a=list(map(int,input().split()))
q=int(input())
for i in range(q):
    bc=list(map(int,input().split()))
list=np.array(a)
sum=list.sum()
ans=[]
for i in range(q):
    sa=bc[1]-bc[0]
    num=a.count(bc[0])
    ans.append(sum+num)
    
for i in range(q):
    print(ans[i])