#include using namespace std; typedef pair P; typedef long long ll; typedef long double ld; const int inf=1e9+7; const ll longinf=1LL<<60; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define F first #define S second constexpr char ln = '\n'; const int mx=200010; const ll mod=1e9+7; int main(){ int n; cin >> n; vector a(n); rep(i,n){ cin >> a[i]; } vector ido(n); rep(i,n){ ido[i] = (i+a[i])%n; } int q; cin >> q; while(q--){ ll k; cin >> k; auto nxt = ido; auto add = a; ll ans = 0; int pos = 0; while(k>0){ if(k%2==1){ ans += add[pos]; pos = nxt[pos]; } auto nx = nxt; auto ad = add; rep(i,n){ nxt[i] = nx[nx[i]]; add[i] = ad[i] + ad[nx[i]]; } k/=2; } cout << ans << ln; } return 0; }