#include #include using namespace std; using namespace atcoder; using S = vector; using F = long long; int mod = 998244353; S op(S a, S b){ return a;} S e(){ return {1, 1, 1}; } S mapping(F f, S x){ for(int i = 0; i < f; i++){ long long a, b, c; a = x[0];b = x[1]; c = x[2]; x = {(a + 1) % mod, (3 * b + 2 * (a + 1) * c) % mod, 3 * c % mod}; } return x; } F composition(F f, F g){ return f + g;} F id(){ return 0; } int main(){ int N, Q; cin >> N >> mod >> Q; vector v(N); for(int i = 0; i < N; i++){ v[i] = {1, 1, 1}; } lazy_segtree seg(v); for(int i = 0; i < Q; i++){ int l, m, r; cin >> l >> m >> r; l--; seg.apply(l, r, 1); vector ans = seg.get(m - 1); cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << '\n'; } }