N=int(input()) A=list(map(int,input().split())) Q=int(input()) P=set() H=[] s=0 while s not in P: P.add(s) H.append(s) s=(s+A[s])%N L=H.index(s)+1 T=[0] for i in range(L): T.append(T[-1]+A[T[-1]%N]) U=[0] for i in range(N-L+1): U.append(U[-1]+A[H[i]]) for _ in range(Q): x=int(input()) if x<=L: print(T[x]) else: R=(x-L) E=R//(len(H)-L+1) F=R%(len(H)-L+1) print(T[-1]+U[-1]*E+U[F])