#line 2 "lib/template.hpp" # pragma GCC optimize("O3") using namespace std; #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; using i128=__int128; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; #define vec(d,T,n,...) vec_##d(T,n,__VA_ARGS__) #define vec_1(T,n,a) vector n(a) #define vec_2(T,n,a,b) vector> n(a,vector(b)) #define vec_3(T,n,a,b,c) vector>> n(a,vector>(b,vector(c))) #define vec_4(T,n,a,b,c,d) vector>>> n(a,vector>>(b,vector>(c,vector(d)))) #define vec_5(T,n,a,b,c,d,e) vector>>>> n(a,vector>>>(b,vector>>(c,vector>(d,vector(e))))) #define vec_6(T,n,a,b,c,d,e,f) vector>>>>> n(a,vector>>>>(b,vector>>>(c,vector>>(d,vector>(e,vector(f)))))) #define vec_7(T,n,a,b,c,d,e,f,g) vector>>>>>> n(a,vector>>>>>(b,vector>>>>(c,vector>>>(d,vector>>(e,vector>(f,vector(g))))))) templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define rall(x) x.rbegin(),x.rend() #define mp make_pair #define pb push_back #define fi first #define se second #define is insert #define bg begin() #define ed end() #define all(x) x.begin(),x.end() void scan(int&a) { cin >> a; } void scan(ll&a) { cin >> a; } void scan(string&a) { cin >> a; } void scan(char&a) { cin >> a; } void scan(uint&a) { cin >> a; } void scan(ull&a) { cin >> a; } void scan(bool&a) { cin >> a; } void scan(ld&a){ cin>> a;} template void scan(vector&a) { for(auto&x:a) scan(x); } void read() {} template void read(Head&head, Tail&... tail) { scan(head); read(tail...); } #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define CHR(...) char __VA_ARGS__; read(__VA_ARGS__); #define DBL(...) double __VA_ARGS__; read(__VA_ARGS__); #define LD(...) ld __VA_ARGS__; read(__VA_ARGS__); #define VC(type, name, ...) vector name(__VA_ARGS__); read(name); #define VVC(type, name, size, ...) vector> name(size, vector(__VA_ARGS__)); read(name); templatevoid print(T a) { cout << a; } template void print(vectora) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}cout< void PRT(T a) { print(a); cout < void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; } template bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template bool chmax(T &x, F y){ if(x T floor(T a, T b) { return a / b - (a % b && (a ^ b) < 0); } template T ceil(T x, T y) { return floor(x + y - 1, y); } template T bmod(T x, T y) { return x - y * floor(x, y); } template pair divmod(T x, T y) { T q = floor(x, y); return {q, x - q * y}; } void YesNo(bool b){ cout<<(b?"Yes":"No")< T isqrt(T x){ T F=sqrtl(x); while((F+1)*(F+1)<=x)F++; while(F*F>x)F--; return F; } template int popcount(T n){ return __builtin_popcountll(n); } template L sum(vc&a){ return accumulate(all(a),L(0)); } template vcsubset(T S){ vcans; for(T x=S;x>0;x=(x-1)&S)ans.pb(x); ans.pb(0); return ans; } template T max(vc&a){ return *max_element(all(a)); } template T min(vc&a){ return *min_element(all(a)); } vvcreadgraph(int n,int m,int off = -1){ vvc g(n); rep(i, m){ int u,v; cin>>u>>v; u+=off,v+=off; g[u].push_back(v); g[v].push_back(u); } return g; } vvc readtree(int n,int off=-1){ return readgraph(n,n-1,off); } template vc presum(vc &a){ vc ret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc &operator+=(vc &a,F b){ for (auto&v:a)v += b; return a; } template vc &operator-=(vc&a,F b){ for (auto&v:a)v-=b; return a; } template vc &operator*=(vc&a,F b){ for (auto&v:a)v*=b; return a; } template constexpr T POW(T a,T b){ T res=1; while(b){ if(b&1)res*=a; a*=a; b/=2; } return res; } constexpr ll ten(ll a){ return POW(10,a); } templateconstexpr T inf=numeric_limits::max()/2-1; int tbit(int32_t x){return x==0?-1:31-__builtin_clz((uint32_t)x);} int lbit(int32_t x){return x==0?-1:__builtin_ctz((uint32_t)x);} int tbit(uint32_t x){return x==0?-1:31-__builtin_clz(x);} int lbit(uint32_t x){return x==0?-1:__builtin_ctz(x);} int tbit(int64_t x){return x==0?-1:63-__builtin_clzll((uint64_t)x);} int lbit(int64_t x){return x==0?-1:__builtin_ctzll((uint64_t)x);} int tbit(uint64_t x){return x==0?-1:63-__builtin_clzll(x);} int lbit(uint64_t x){return x==0?-1:__builtin_ctzll(x);} int tbit(int32_t x,int p){return p<0?-1:tbit((int32_t)(x&(p>=31?~0u:(1u<<(p+1))-1)));} int lbit(int32_t x,int p){return p>31?-1:lbit((int32_t)(x&(~0u<=31?~0u:(1u<<(p+1))-1)));} int lbit(uint32_t x,int p){return p>31?-1:lbit((uint32_t)(x&(~0u<=63?~0ULL:(1ULL<<(p+1))-1)));} int lbit(int64_t x,int p){return p>63?-1:lbit((int64_t)(x&(~0ULL<=63?~0ULL:(1ULL<<(p+1))-1)));} int lbit(uint64_t x,int p){return p>63?-1:lbit((uint64_t)(x&(~0ULL<>(std::istream& is, __int128& x) { std::streambuf* sb = is.rdbuf(); int c = sb->sgetc(); while (c <= ' ') c = sb->snextc(); bool neg = false; if (c == '-') { neg = true; c = sb->snextc(); } unsigned __int128 v = 0; while ((unsigned)(c - '0') < 10) { v = v * 10 + (c - '0'); c = sb->snextc(); } x = neg ? -(__int128)v : (__int128)v; return is; } std::ostream& operator<<(std::ostream& os, __int128 x) { std::streambuf* sb = os.rdbuf(); if (x == 0) { sb->sputc('0'); return os; } char buf[40]; int pos = 39; bool neg = x < 0; unsigned __int128 v = neg ? -(unsigned __int128)x : (unsigned __int128)x; while (v) { buf[--pos] = char('0' + (v % 10)); v /= 10; } if (neg) buf[--pos] = '-'; sb->sputn(buf + pos, 39 - pos); return os; } #ifdef LOCAL template std::ostream& operator<<(std::ostream& os, const std::pair& p); template std::ostream& operator<<(std::ostream& os, const std::vector& v); template std::ostream& operator<<(std::ostream& os, const std::deque& dq); template std::ostream& operator<<(std::ostream& os, const std::list& lst); template std::ostream& operator<<(std::ostream& os, const std::set& s); template std::ostream& operator<<(std::ostream& os, const std::unordered_set& s); template std::ostream& operator<<(std::ostream& os, const std::map& m); template std::ostream& operator<<(std::ostream& os, const std::unordered_map& m); template std::ostream& operator<<(std::ostream& os, std::stack st); template std::ostream& operator<<(std::ostream& os, std::queue q); template std::ostream& operator<<(std::ostream& os, const std::array& a); template std::ostream& operator<<(std::ostream& os, std::priority_queue pq); #define dbg(...) debug_func(0, #__VA_ARGS__, __VA_ARGS__) template void debug_func(int i, T name) { cout << endl; } template void debug_func(int i, const T1 &name, const T2 &a, const T3 &...b) { for ( ; name[i] != ',' && name[i] != '\0'; i++ ) cout << name[i]; cout << ":" << a << " "; debug_func(i + 1, name, b...); } // pair template std::ostream& operator<<(std::ostream& os, const std::pair& p) { return os << "(" << p.first << ", " << p.second << ")"; } // vector template std::ostream& operator<<(std::ostream& os, const std::vector& v) { os << "["; for (size_t i = 0; i < v.size(); ++i) { if (i > 0) os << ", "; os << v[i]; } os << "]"; return os; } template std::ostream& operator<<(std::ostream& os, const std::deque& dq) { os << "["; for (size_t i = 0; i < dq.size(); ++i) { if (i > 0) os << ", "; os << dq[i]; } os << "]"; return os; } template std::ostream& operator<<(std::ostream& os, const std::list& lst) { os << "["; bool first = true; for (const auto& x : lst) { if (!first) os << ", "; os << x; first = false; } os << "]"; return os; } template std::ostream& operator<<(std::ostream& os, const std::set& s) { os << "{"; bool first = true; for (const auto& x : s) { if (!first) os << ", "; os << x; first = false; } os << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::unordered_set& s) { os << "{"; bool first = true; for (const auto& x : s) { if (!first) os << ", "; os << x; first = false; } os << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::map& m) { os << "{"; bool first = true; for (const auto& kv : m) { if (!first) os << ", "; os << kv; first = false; } os << "}"; return os; } template std::ostream& operator<<(std::ostream& os, const std::unordered_map& m) { os << "{"; bool first = true; for (const auto& kv : m) { if (!first) os << ", "; os << kv; first = false; } os << "}"; return os; } template std::ostream& operator<<(std::ostream& os, std::stack st) { os << "["; bool first = true; while (!st.empty()) { if (!first) os << ", "; os << st.top(); st.pop(); first = false; } os << "]"; return os; } template std::ostream& operator<<(std::ostream& os, std::queue q) { os << "["; bool first = true; while (!q.empty()) { if (!first) os << ", "; os << q.front(); q.pop(); first = false; } os << "]"; return os; } template std::ostream& operator<<(std::ostream& os, std::priority_queue pq) { os << "["; while (!pq.empty()) { os << pq.top() << (pq.size() > 1 ? ", " : ""); pq.pop(); } return os << "]"; } template std::ostream& operator<<(std::ostream& os, const std::array& a) { os << "["; for (std::size_t i = 0; i < N; ++i) { if (i > 0) os << ", "; os << a[i]; } os << "]"; return os; } #else #define dbg(...) 1111 #endif #line 4 "lib/graph/base.hpp" struct Unweighted{ Unweighted()=default; Unweighted(int){} operator int()const{return 1;} }; template struct edge{ int from,to,id; [[no_unique_address]] T cost; #ifdef LOCAL friend ostream&operator<<(ostream&os,const edge&e){ return os<<"{from:"<struct is_edge:false_type{}; templatestruct is_edge().from),decltype(declval().to),decltype(declval().id),decltype(declval().cost)>>:true_type{}; struct empty_storage{}; template struct static_graph{ constexpr static bool directed(){return is_directed;} using edge=conditional_t::value,T,::edge>; using cost_t=decltype(declval().cost); private: int n,m,added=0; mutable bool csr_built=false; [[no_unique_address]] mutable conditional_t inv_built{}; vc_all_edges; mutable vccsr_start; mutable vccsr_edge; [[no_unique_address]] mutable conditional_t,empty_storage>inv_start; [[no_unique_address]] mutable conditional_t,empty_storage>inv_edge; public: static_graph(int n):n(n),m(-1),csr_start(n+1){} static_graph(int n,int m):n(n),m(m),csr_start(n+1){_all_edges.reserve(m);} void add_edge(const edge&e){ assert(0<=e.from&&e.from void input(int edge_count){ rep(i,edge_count){ INT(a,b); a-=substract; b-=substract; add_edge(a,b); } } void build()const{ if(csr_built)return; csr_built=true; csr_start.assign(n+1,0); for(auto&e:_all_edges){ csr_start[e.from]++; if constexpr(!is_directed)csr_start[e.to]++; } rep(i,n)csr_start[i+1]+=csr_start[i]; csr_edge.resize(csr_start[n]); for(auto it=_all_edges.rbegin();it!=_all_edges.rend();++it){ auto&e=*it; csr_edge[--csr_start[e.from]]=e; if constexpr(!is_directed)csr_edge[--csr_start[e.to]]={e.to,e.from,e.id,e.cost}; } } void build_inv()const{ if constexpr(!is_directed){ build(); return; }else{ if(inv_built)return; inv_built=true; inv_start.assign(n+1,0); for(auto&e:_all_edges){ inv_start[e.to]++; } rep(i,n)inv_start[i+1]+=inv_start[i]; inv_edge.resize(inv_start[n]); for(auto it=_all_edges.rbegin();it!=_all_edges.rend();++it){ auto&e=*it; inv_edge[--inv_start[e.to]]={e.to,e.from,e.id,e.cost}; } } } const vc&all_edges()const{return _all_edges;} int edge_size()const{return (int)_all_edges.size();} edge get_edge(int id)const{ assert(0<=id&&id struct span{ E*l; E* r; E*begin()const{return l;} E*end()const{return r;} int size()const{return r-l;} E&operator[](int i){return l[i];} const E&operator[](int i)const{return l[i];} }; auto operator[](int u){ assert(0<=u&&u{csr_edge.data()+csr_start[u],csr_edge.data()+csr_start[u+1]}; } auto operator[](int u)const{ assert(0<=u&&u{csr_edge.data()+csr_start[u],csr_edge.data()+csr_start[u+1]}; } auto inv(int u){ assert(0<=u&&u{inv_edge.data()+inv_start[u],inv_edge.data()+inv_start[u+1]}; } } auto inv(int u)const{ assert(0<=u&&u{inv_edge.data()+inv_start[u],inv_edge.data()+inv_start[u+1]}; } } int size()const{return n;} templatevvcadj()const{ vvcres(n,vc(n)); for(auto&e:all_edges()){ res[e.from][e.to]=e.cost; if(directed()==false)res[e.to][e.from]=e.cost; } return res; } void clear(){ added=0; csr_built=false; if constexpr(is_directed)inv_built=false; _all_edges.clear();_all_edges.shrink_to_fit(); csr_start.assign(n+1,0);csr_start.shrink_to_fit(); csr_edge.clear();csr_edge.shrink_to_fit(); if constexpr(is_directed){ inv_start.clear();inv_start.shrink_to_fit(); inv_edge.clear();inv_edge.shrink_to_fit(); } } template void sort(int i,F f){ assert(0<=i&&i void sort_inv(int i,F f){ assert(0<=i&&i static_graphextract(F f)const{ static_graphres(n); for(auto&e:_all_edges)if(f(e))res.add_edge(e); return res; } template static_graph<1,T>reorder(F f)const{ static_graph<1,T>res(n); for(auto&e:_all_edges){ if(f(e))res.add_edge(e); else res.add_edge({e.to,e.from,e.id,e.cost}); } return res; } }; #line 3 "lib/math/barrett.hpp" struct Barrett{ using u64=uint64_t; using u32=uint32_t; using i128=__int128_t; u64 m; int mod; void set(int mod_){ assert(mod_>0); mod=mod_; m=(i128(1)<<64)/mod; } unsigned reduce(uint64_t x){ assert(mod>0); x-=(((i128)x*m)>>64)*mod; return x struct DynamicModInt{ using u32=uint32_t; using u64=uint64_t; u32 val; DynamicModInt():val(0){} DynamicModInt(ll x){ int v=x%get_mod(); if(v<0)v+=get_mod(); val=v; } static DynamicModInt raw(int v){ assert(v>=0); DynamicModInt mi; mi.val=v; return mi; } DynamicModInt &operator+=(const DynamicModInt&m){ if((val+=m.val)>=get_mod())val-=get_mod(); return *this; } DynamicModInt &operator-=(const DynamicModInt&m){ if((val+=(get_mod()-m.val))>=get_mod())val-=get_mod(); return *this; } DynamicModInt &operator*=(const DynamicModInt&m){ val=rem(u64(val)*m.val); return *this; } DynamicModInt &operator/=(const DynamicModInt&m){ val=rem(u64(val)*m.inv().val); return *this; } DynamicModInt operator-() const{ return DynamicModInt(-val); } DynamicModInt operator+() const { return *this; } friend DynamicModInt operator+(DynamicModInt lhs, const DynamicModInt& rhs){ return lhs+=rhs; } friend DynamicModInt operator-(DynamicModInt lhs, const DynamicModInt& rhs){ return lhs-=rhs; } friend DynamicModInt operator*(DynamicModInt lhs, const DynamicModInt& rhs){ return lhs*=rhs; } friend DynamicModInt operator/(DynamicModInt lhs,const DynamicModInt&rhs){ return lhs/=rhs; } bool operator==(const DynamicModInt&p) const{ return p.val==val; } bool operator!=(const DynamicModInt&p) const{ return p.val!=val; } DynamicModInt pow(int64_t n) const{ DynamicModInt res(1),mul(val); while(n){ if(n%2)res*=mul; mul*=mul; n/=2; } return res; } friend ostream&operator<<(ostream&os,const DynamicModInt&p){ os<>(istream&is,DynamicModInt&p){ int64_t x; is>>x; p=DynamicModInt(x); return is; } DynamicModInt inv()const{ int a=val,b=get_mod(),u=1,v=0,t; #ifdef LOCAL assert(gcd(a,b)==1); #endif while(b>0){ t=a/b; swap(a-=t*b,b); swap(u-=t*v,v); } return DynamicModInt(u); } inline static u32 rem(u64 x){return BarrettReduction().reduce(x);} static inline int &get_mod(){ static int mod=0; return mod; } static void set_mod(int md){ assert(0 struct Binom{ private: inline static vector_fact={1},_invfact={1},_invs={0}; public: static void build(int n){ if(n<(int)_fact.size())return; int old=_fact.size(); _fact.resize(n+1); _invfact.resize(n+1); _invs.resize(n+1); auto mod=mint::get_mod(); for(int i=old;i<=n;i++){ _fact[i]=_fact[i-1]*i; if(i==1)_invs[i]=1; else _invs[i]=-_invs[mod%i]*(mod/i); _invfact[i]=_invfact[i-1]*_invs[i]; } } static mint fact(int i){ assert(i>=0); build(i); return _fact[i]; } static mint invfact(int i){ assert(i>=0); build(i); return _invfact[i]; } static mint inv(int i){ assert(i>0); build(i); return _invs[i]; } static mint C(int a,int b){//aCb if(a<0||b<0||a-b<0)return mint(0); build(a); return _fact[a]*_invfact[b]*_invfact[a-b]; } static mint P(int a,int b){ if(a pair inv(T x,T m){ T a1,a2; T res=extgcd(x,m,a1,a2); return {a1,m/res}; } template pair mod_solve(T a,T b,T m){//return x s.t. ax=b mod m a%=m,b%=m;if(a<0)a+=m;if(b<0)b+=m; T g=gcd(gcd(a,b),m); a/=g,b/=g,m/=g; if(gcd(a,m)>1)return {-1,-1}; return {(inv(a,m).first*b)%m,inv(a,m).second}; } //https://nyaannyaan.github.io/library/modulo/mod-sqrt.hpp.html int64_t mod_sqrt(const int64_t &a, const int64_t &p) { assert(0 <= a && a < p); if (a < 2) return a; using Mint = DynamicModInt<409075245>; Mint::set_mod(p); if (Mint(a).pow((p - 1) >> 1) != 1) return -1; Mint b = 1, one = 1; while (b.pow((p - 1) >> 1) == 1) b += one; int64_t m = p - 1, e = 0; while (m % 2 == 0) m >>= 1, e += 1; Mint x = Mint(a).pow((m - 1) >> 1); Mint y = Mint(a) * x * x; x *= a; Mint z = Mint(b).pow(m); while (y != 1) { int64_t j = 0; Mint t = y; while (t != one) { j += 1; t *= t; } z = z.pow(int64_t(1) << (e - j - 1)); x *= z; z *= z; y *= z; e = j; } return x.val; } #line 4 "lib/math/static-mod-int.hpp" template struct StaticModInt{ using u32=uint32_t; using u64=uint64_t; u32 val; StaticModInt():val(0){} StaticModInt(ll x){ int v=x%mod; if(v<0)v+=mod; val=v; } constexpr static uint32_t get_mod(){ return mod; } static StaticModInt raw(int v){ assert(v>=0); StaticModInt mi; mi.val=v; return mi; } StaticModInt &operator+=(const StaticModInt&m){ if((val+=m.val)>=mod)val-=mod; return *this; } StaticModInt &operator-=(const StaticModInt&m){ if((val+=(mod-m.val))>=mod)val-=mod; return *this; } StaticModInt &operator*=(const StaticModInt&m){ val=u64(val)*m.val%mod; return *this; } StaticModInt &operator/=(const StaticModInt&m){ val=u64(val)*m.inv().val%mod; return *this; } StaticModInt operator-() const{ return StaticModInt(mod-val); } StaticModInt operator+() const { return *this; } friend StaticModInt operator+(StaticModInt lhs, const StaticModInt& rhs){ return lhs+=rhs; } friend StaticModInt operator-(StaticModInt lhs, const StaticModInt& rhs){ return lhs-=rhs; } friend StaticModInt operator*(StaticModInt lhs, const StaticModInt& rhs){ return lhs*=rhs; } friend StaticModInt operator/(StaticModInt lhs,const StaticModInt&rhs){ return lhs/=rhs; } bool operator==(const StaticModInt&p) const{ return p.val==val; } bool operator!=(const StaticModInt&p) const{ return p.val!=val; } StaticModInt pow(int64_t n) const{ StaticModInt res(1),mul(val); while(n){ if(n%2)res*=mul; mul*=mul; n/=2; } return res; } friend ostream&operator<<(ostream&os,const StaticModInt&p){ os<>(istream&is,StaticModInt&p){ int64_t x; is>>x; p=StaticModInt(x); return is; } StaticModInt inv()const{ int a=val,b=mod,u=1,v=0,t; #ifdef LOCAL assert(gcd(a,b)==1); #endif while(b>0){ t=a/b; swap(a-=t*b,b); swap(u-=t*v,v); } return StaticModInt(u); } }; #line 4 "a.cpp" using mint=StaticModInt<998244353>; void solve(){ using B=Binom; LL(x,y,z,w); if(z==0)swap(x,z),swap(y,w); B::build(2e6); PRT(B::C(x,z)*B::C(y,w)*B::fact(x-z)*B::fact(y-w)*(B::C(x-z+y-w-1,x-z))); } signed main(){ dbg("==============="s); #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif cin.tie(0)->sync_with_stdio(0); cout<> t; while(t--)solve(); }