#include using namespace std; using ll=long long; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin>>N>>Q; string S; cin>>S; vector R(N+1,0),D(N+1,0); for(int i=0;i>H>>W>>P; cout<<(W+P)%N<<'\n'; } }else if(R[N]==0){ while(Q--){ ll H,W,P; cin>>H>>W>>P; cout<<(H+P)%N<<'\n'; } }else{ while(Q--){ ll H,W,P; cin>>H>>W>>P; H+=D[P]; W+=R[P]; ll cntH=(H-1)/D[N]*N+ll(lower_bound(D.begin(),D.end(),(H-1)%D[N]+1)-D.begin()); ll cntW=(W-1)/R[N]*N+ll(lower_bound(R.begin(),R.end(),(W-1)%R[N]+1)-R.begin()); if(cntH