import sys import io, os input = sys.stdin.buffer.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) A = list(map(int, input().split())) X = [0]*(n+2) used = {} x = 0 X[0] = x for i in range(n+1): r = x%n x += A[r] X[i+1] = x if r in used: c = i-used[r] t = used[r] break else: used[r] = i cum = X[t:t+c+1] s = cum[-1]-cum[0] Q = int(input()) for i in range(Q): k = int(input()) if k < t: print(X[k]) else: q, r = divmod(k-t, c) ans = X[t]+s*q+cum[r]-cum[0] print(ans)