#include using namespace std; typedef long long ll; template bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,-1,0}; int dy[4]={1,0,0,-1}; long double eps = 1e-6; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll n; cin>>n; ll a[n]; for(int i=0;i>a[i]; } ll cnt[n+2]={}; cnt[0] = 0; ll now = 0; int r = 0; int used[n+2]={}; used[0] = 1; ll cy = -1; ll st = -1; int las = 0; for(int i=1;i<=n;i++){ now += a[r]; r = (r+a[r])%n; if(used[r]){ st = used[r]-1; cy = i+1 - used[r]; cnt[i] = now; las = i; break; } used[r] = i+1; cnt[i] = now; } int q; cin>>q; while(q--){ ll k; cin>>k; if(k <= st){ cout << cnt[k] << "\n"; continue; } ll ans = cnt[st]; k -= st; ans += (cnt[las] - cnt[st]) * (k/cy); k %= cy; ans += cnt[st+k] - cnt[st]; cout << ans << "\n"; } cerr << 61919700120 << endl; }