import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) Q = int(readline()) dp1 = [[0] * N for i in range(61)] dp2 = [[0] * N for i in range(61)] for i in range(N): dp1[0][i] = (i + A[i]) % N dp2[0][i] = A[i] for n in range(60): for i in range(N): dp1[n + 1][i] = dp1[n][dp1[n][i]] dp2[n + 1][i] = dp2[n][i] + dp2[n][dp1[n][i]] for _ in range(Q): K = int(readline()) now = 0 ans = 0 for i in range(60): if (K >> i) & 1: ans += dp2[i][now] now = dp1[i][now] print(ans)