#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/D[N]*N+ll(lower_bound(D.begin(),D.end(),H%D[N])-D.begin()); ll cntW=W/R[N]*N+ll(lower_bound(R.begin(),R.end(),W%R[N])-R.begin()); if(cntH