#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; typedef pair PL; constexpr ll INF = (1LL << 60); int main() { int n; cin >> n; vector a(n); rep(i,n) cin >> a[i]; vector> to(61, vector(n, 0)); for (int i = 0; i < n; i++) to[0][i] = a[i]; for (int i = 0; i < 60; i++) { for (int j = 0; j < n; j++) to[i + 1][j] = to[i][j] + to[i][(j + to[i][j]) % n]; } int q; cin >> q; while (q--) { ll k; cin >> k; ll res = 0; for (int j = 0; j < 60; j++) { if (k & (1LL << j)) res += to[j][res % n]; } cout << res << endl; } return 0; }