#include #include #include using mint = atcoder::modint998244353; struct F { mint a, b; mint eval(mint x) const { return a * x + b; } }; F compose(F f, F g) { return F{ g.a * f.a, g.a * f.b + g.b }; } F id() { return F{ 1, 0 }; } 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] = compose(seg[2 * k + 0][s], seg[2 * k + 1][s]); seg[k][1 * siz + s] = compose(seg[2 * k + 1][s], seg[2 * k + 0][s]); } } while (q --> 0) { int l, r, p, x; std::cin >> l >> r >> p >> x; auto query = [&](auto query, int tl, int tr, int k, int bit) -> F { if (r <= tl or tr <= l) return id(); if (l <= tl and tr <= r) return seg[k][p & (bit - 1)]; bit >>= 1; const bool flip = p & bit; const int tm = (tl + tr) >> 1; F sl = query(query, tl, tm, 2 * k + flip, bit); F sr = query(query, tm, tr, 2 * k + not flip, bit); return compose(sl, sr); }; std::cout << query(query, 0, n, 1, n).eval(x).val() << '\n'; } return 0; }