#include using namespace std; template int sz(T&& a) { return int(size(forward(a))); } template using vc = vector; template using vvc = vc>; using ll = int64_t; using vi = vc; using pii = pair; using uint = uint32_t; using ull = uint64_t; mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); template struct ycr { F f; template explicit ycr(T&& f_) : f(forward(f_)) {} template decltype(auto) operator()(Args&&... args) { return f(ref(*this), forward(args)...); } }; template decltype(auto) yc(F&& f) { return ycr>(forward(f)); } /** * Author: Hanfei Chen * Date: 2023-11-30 * Description: Very fast factorization. * Source: https://judge.yosupo.jp/submission/110118 * Status: Tested with https://judge.yosupo.jp/problem/factorize */ struct montgomery { using T = ull; /// start-hash using u128 = __uint128_t; T n, n2, r, t, e; montgomery(T n_) : n(n_) { assert(n < (T(1) << 62)); assert(n % 2 == 1); n2 = n * 2; r = n & 3; for (int z = 0; z < 5; z++) r *= 2-n*r; r = -r; assert(r * n == T(-1)); t = -T(n) % n; e = T(-u128(n) % n); } /// end-hash T reduce(u128 a) const { /// start-hash return T((a + u128(T(a) * r) * n) >> 64); } T mult(T a, T b) const { return reduce(u128(a) * b); } /// end-hash T encode(T a) const { /// start-hash return mult(a, e); } T decode(T a) const { a = reduce(a); return a < n ? a : a-n; } /// end-hash T pow(T a, ll b) const { /// start-hash assert(b >= 0); T v = t; while (b) { if (b & 1) v = mult(v, a); a = mult(a, a); b >>= 1; } return v; } /// end-hash bool is_prime() const { assert(n >= 3); assert(n & 1); T d = n-1; /// start-hash int s = __builtin_ctzll(d); d >>= s; auto check = [&](T a) -> int { a %= n; if (a == 0) return 1; T p = pow(encode(a), d); if (decode(p) == 1 || decode(p) == n-1) return 0; for (int z = 0; z < s; z++) { p = mult(p, p); if (decode(p) == n-1) return 0; } return -1; }; /// end-hash for (T a : {2,325,9375,28178,450775,9780504,1795265022}) { /// start-hash int w = check(a); if (w) return w == 1; } return true; /// end-hash } ull pollard() const { assert(n >= 3); assert(n & 1); if (is_prime()) return n; /// start-hash while (true) { T c = mt() % (n-1) + 1; T y = mt() % (n-1) + 1; auto f = [&](T a) -> T { return reduce(u128(a) * a + c); }; for (T s = 1; ; s *= 2) { T x = n2-y; int m = int(min(T(1) << (__lg(n)/6), s)); for (int i = 0; i < int(s/m); i++) { T w = t, z = y; for (int j = 0; j < m; j++) { y = f(y); w = mult(w, y+x); } T g = __gcd(decode(w), n); if (g != 1) { if (g < n) return g; for (int j = 0; j < m; j++) { z = f(z); if ((g = __gcd(decode(z+x), n)) != 1) { if (g < n) return g; goto fail; } } assert(false); } } } fail:; } /// end-hash } // facs = {prime factors of (n-1)} bool is_root(T g, const vc& facs) { /// start-hash assert(g >= 2); g = encode(g); for (auto f : facs) { if (decode(pow(g, (n-1) / f)) == 1) return false; } return true; } /// end-hash }; bool is_prime(ull n) { /// start-hash if (n <= 1) return false; if (n == 2) return true; if (n % 2 == 0) return false; return montgomery(n).is_prime(); } /// end-hash ull get_divisor(ull n) { /// start-hash assert(n > 1); if (n % 2 == 0) return 2; return montgomery(n).pollard(); } /// end-hash vc factorize(ull n) { /// start-hash vc res; yc([&](auto self, ull v) -> void { if (v == 1) return; ull d = get_divisor(v); if (d == v) { res.push_back(d); return; } self(d); self(v/d); })(n); return res; } /// end-hash #include using namespace atcoder; using mint = modint998244353; mint dp[1<<15]; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cout << fixed << setprecision(20); int T; ll m; cin >> T >> m; ll x = m; auto res = factorize(x); map mp; for(auto x:res) mp[x]++; vector> di; for(auto p:mp) di.push_back({p.first,p.second}); while(T){ T--; ll i,j,n,b,c,d; cin >> n >> b >> c >> d; vector a(n); vector w(n); for(i=0;i> a[i]; w[0] = b; for(i=1;i>j&1)) (dp[i] *= dp[i^(1<>j&1) c = 1 - c; } if(!c) (ans += dp[i]); else (ans -= dp[i]); } if(m==1) ans--; cout << ans.val() << "\n"; } // while (T--) { // ull n; // cin >> n; // auto res = factorize(n); // sort(res.begin(), res.end()); // cout << res.size(); // for (auto p : res) { // cout << ' ' << p; // } // cout << '\n'; // } // return 0; }