N=int(input()) A=[int(x) for x in input().split()] D=dict() a=0 t=0 D[0]=(0,0) p=0 ans = [] while True: p+=1 a+=A[a%N] ans.append(a) if not a%N in D: D[a%N]=(a,p) else: break cycle = p - D[a%N][1] score = a - D[a%N][0] def res(K): if p>K-1: print(ans[K-1]) else: b = a + ((K-p)//cycle)*score q = p + ((K-p)//cycle)*cycle if K>q: b += ans[K-q+D[a%N][1]-1] - D[a%N][0] print(b) for _ in range(int(input())): res(int(input()))