from ast import Name N = int(input()) A = list(map(int,input().split())) B = [0] setB = {0} cur = 0 while True: ncur = (cur+A[cur%N])%N if ncur in setB:break setB.add(ncur) B.append(ncur) cur = ncur ind = B.index(ncur) B0 = B[:ind] B1 = B[ind:] S = len(B0) if S>0: cumA0 = [0]*S cumA0[0] = A[B0[0]] for i in range(1,S): cumA0[i] = cumA0[i-1]+A[B0[i]] T = len(B1) cumA1 = [0]*T cumA1[0] = A[B1[0]] for i in range(1,T): cumA1[i] = cumA1[i-1]+A[B1[i]] Q = int(input()) for _ in range(Q): K = int(input()) ans = 0 if K<=S: ans = cumA0[K-1] else: if S>0: ans = cumA0[S-1] K -= S q = K//T r = K%T ans += q*cumA1[T-1] if r>0: ans += cumA1[r-1] print(ans)