from typing import Sequence as Seq def argsort(a): return sorted(list(range(len(a))), key=lambda i: a[i]) def argperm(p): a = [0] * len(p) for i, j in enumerate(p): a[j] = i return a def rankify(a): return argperm(argsort(a)) import sys V = sys.version_info _39 = False _310 = False _311 = False _312 = False if V.major == 3: _39 = V.minor >= 9 _310 = V.minor >= 10 _311 = V.minor >= 11 _312 = V.minor >= 12 if _39: li = list tup = tuple dic = dict st = set ty = type else: from typing import ( List, Tuple, Type, Dict, Set, ) li = List tup = Tuple dic = Dict st = Set ty = Type li = list tup = tuple from typing import TypeVar, Generic as Gen T = TypeVar('T') from typing import Iterable as Iter from typing import Callable as Fn import sys sys.setrecursionlimit(1 << 20) def unique(a: Iter[T]) -> li[T]: return sorted(set(a)) from bisect import bisect_left as lb, bisect_right as ub if _311: from typing import Self else: Self = TypeVar('Self') inf = float('inf') def fancy(a, p): return [a[i] for i in p] class FG: w: int j: int s: li[int] # 1-indexed with centinel ws: int def __init__(self, f: li[int], x: li[int], u: int): p = [-1] * len(f) self.s = s = [0] i = 0 while p[u] == -1: p[u] = i i += 1 s.append(s[-1] + x[u]) u = f[u] j = p[u] self.j, self.w, self.ws = j, i - j, s[i] - s[j] def sum(self, k: int) -> int: j, s = self.j, self.s if k <= j: return s[k] q, r = divmod(k - j, self.w) return q * self.ws + s[j + r] def main(): n = int(input()) x = list(map(int, input().split())) f = [(i + x[i]) % n for i in range(n)] fg = FG(f, x, 0) q = int(input()) for _ in range(q): k = int(input()) print(fg.sum(k)) main()