#include #include #include using mint = atcoder::modint998244353; struct F { mint a, b; static F op(F f, F g) { return F{ g.a * f.a, g.a * f.b + g.b }; } static F e() { return F{ 1, 0 }; } mint eval(mint x) { return a * x + b; } }; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int n, q; std::cin >> n >> q; std::vector> seg(2 * n); for (int i = 0; i < n; ++i) { int a, b; std::cin >> a >> b; seg[n + i] = { F { a, b } }; } for (int k = n - 1; k >= 1; --k) { const int siz = seg[2 * k].size(); seg[k].resize(2 * siz); for (int s = 0; s < siz; ++s) { seg[k][0 * siz + s] = F::op(seg[2 * k + 0][s], seg[2 * k + 1][s]); seg[k][1 * siz + s] = F::op(seg[2 * k + 1][s], seg[2 * k + 0][s]); } } auto query = [&](auto query, int ql, int qr, int tl, int tr, int k, int p, int bit) -> F { if (qr <= tl or tr <= ql) return F::e(); if (ql <= tl and tr <= qr) return seg[k][p]; const int flip = p & bit; const int tm = (tl + tr) >> 1; if (flip) { F sl = query(query, ql, qr, tl, tm, 2 * k + 1, p ^ flip, bit >> 1); F sr = query(query, ql, qr, tm, tr, 2 * k + 0, p ^ flip, bit >> 1); return F::op(sl, sr); } else { F sl = query(query, ql, qr, tl, tm, 2 * k + 0, p ^ flip, bit >> 1); F sr = query(query, ql, qr, tm, tr, 2 * k + 1, p ^ flip, bit >> 1); return F::op(sl, sr); } }; while (q --> 0) { int l, r, p, x; std::cin >> l >> r >> p >> x; std::cout << query(query, l, r, 0, n, 1, p, n >> 1).eval(x).val() << '\n'; } return 0; }