#include using namespace std; template class Doubling{ using X=typename Monoid::value_type; int n; bool is_prepared; using P=pair; static constexpr P unit={-1,Monoid::unit()}; vector> DP; P k_move(const P&a,int k){ if(a.first==-1)return a; const auto [now,val]=a; const auto [nxt,cost]=DP[k][now]; return {nxt,Monoid::op(val,cost)}; } void build(){ is_prepared=true; for(int k=0;k(n,unit)); } void add(int from,int to,X x){ assert(!is_prepared); assert(-1<=to and to>=1) if(step&1)res=k_move(res,k); return res; } }; template struct Group_Add { using value_type = X; static constexpr X op(const X &x, const X &y) noexcept { return x + y; } static constexpr X inverse(const X &x) noexcept { return -x; } static constexpr X power(const X &x, long long n) noexcept { return X(n) * x; } static constexpr X unit() { return X(0); } static constexpr bool commute = true; }; using GA=Group_Add; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin>>n; Doubling db(n); for(int i=0;i>a; db.add(i,(i+a)%n,a); } int q;cin>>q; while(q--){ long long k;cin>>k; cout<< db.calc(0,k).second <<"\n"; } }