N = int(input()) A = list(map(int,input().split())) b, c, B = [], [], set() X = 0 while True: r = X%N X += A[r] if r in B: id = b.index(r) roop = len(b)-id sm = X-c[id] break else: B.add(r) b.append(r) c.append(X) Q = int(input()) for i in range(Q): K = int(input()) if K <= len(b): print(c[K-1]) else: print(c[id]+sm*((K-1-id)//roop) + c[id+((K-1-id)%roop)]-c[id])