#include using namespace std; #include "atcoder/modint" #include "atcoder/lazysegtree" using namespace atcoder; using mint=modint; using S=tuple; using F=tuple; S op(S a, S b){ return make_tuple(get<0>(a)+get<0>(b),get<1>(a)+get<1>(b),get<2>(a)+get<2>(b)); } S e(){ return make_tuple(0,0,0); } S mapping(F f, S x){ return make_tuple( get<0>(x)+get<0>(f), get<1>(f)*get<1>(x)+get<2>(f)*get<0>(x)*get<2>(x)+get<3>(f)*get<2>(x), get<4>(f)*get<2>(x) ); } F composition(F f, F g){ return make_tuple( get<0>(f)+get<0>(g), get<1>(f)*get<1>(g), get<1>(f)*get<2>(g)+get<2>(f)*get<4>(g), get<1>(f)*get<3>(g)+get<2>(f)*get<0>(g)*get<4>(g)+get<3>(f)*get<4>(g), get<4>(f)*get<4>(g) ); } F id(){ return make_tuple( 0,1,0,0,1 ); } int main(void) { int n,b,q; cin >> n >> b >> q; mint::set_mod(b); vector v(n,make_tuple(1,1,1)); lazy_segtree s(v); while(q--){ int l,m,r; cin >> l >> m >> r; --l; --m; --r; s.apply(l,r+1,make_tuple(1,3,2,2,3)); auto ans=s.get(m); cout << get<0>(ans).val() << " " << get<1>(ans).val() << " " << get<2>(ans).val() << endl; } return 0; }