#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; const long long MOD = 998244353; struct linear{ long long a, b; linear(){ a = 1; b = 0; } linear(int a, int b): a(a), b(b){ } }; int value(linear A, int x){ return (A.a * x + A.b) % MOD; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, Q; cin >> N >> Q; vector f(N); for (int i = 0; i < N; i++){ int a, b; cin >> a >> b; f[i] = linear(a, b); } for (int i = 0; i < Q; i++){ int l, r, p, x; cin >> l >> r >> p >> x; for (int j = l; j < r; j++){ x = value(f[j ^ p], x); } cout << x << "\n"; } }