#include #if __has_include() #include #endif namespace ttl{ using namespace std; using f80=long double; using i64=int64_t; using u64=uint64_t; template struct MyModInt{ i64 vl; static constexpr i64 get_mod(){ return mod; } i64 val(){ return vl; } MyModInt(i64 vl_=0):vl(vl_%mod){} MyModInt operator-(){ return (vl==0)?0:mod-vl; } MyModInt operator+(MyModInt rhs){ return MyModInt(*this)+=rhs; } MyModInt operator-(MyModInt rhs){ return MyModInt(*this)-=rhs; } MyModInt operator*(MyModInt rhs){ return MyModInt(*this)*=rhs; } MyModInt operator/(MyModInt rhs){ return MyModInt(*this)/=rhs; } MyModInt pow(i64 rhs){ MyModInt res=1,now=(*this); while(rhs){ res*=((rhs&1)?now:1),now*=now,rhs>>=1; } return res; } MyModInt& operator+=(MyModInt rhs){ vl+=rhs.vl,vl-=((vl>=mod)?mod:0); return (*this); } MyModInt& operator-=(MyModInt rhs){ vl+=((vl using ModInt= #if __has_include() atcoder::static_modint; #else MyModInt; #endif template std::ostream& operator<<(std::ostream& os,ModInt x){ return os<<(x.val()); } template std::istream& operator>>(std::istream& is,ModInt& x){ i64 t; is>>t,x=t; return is; } template void Scan_(T& a){ cin>>a; } template void Scan_(pair& a){ Scan_(a.first),Scan_(a.second); } template void Scan_(vector& a){ for(auto& v:a){ Scan_(v); } } template void Scan_(vector>& a){ for(auto& v:a){ for(auto& u:v){ Scan_(u); } } } void Scan(){} template void Scan(T& n,Args&... args){ Scan_(n),Scan(args...); } template void Print_(T a){ cout< void Print_(pair a){ Print_(a.first),cout<<" ";Print_(a.second); } void Print_(f80 a){ printf("%.10Lf",a); } template void Print(vector a){ for(size_t i=0;i void Print(vector> a){ for(auto& v:a){ for(size_t i=0;i void Print(T a){ Print_(a),cout<<"\n"; } template void Print(T a,Args... args){ Print_(a),cout<<" ",Print(args...); } template struct multi_dim_vector{ using type=vector::type>; }; template struct multi_dim_vector{ using type=T; }; template vector MakeVec(int n,Arg&& arg){ return vector(n,arg); } template class multi_dim_vector::type MakeVec(int n,Args&&... args){ return typename multi_dim_vector::type(n,MakeVec(args...)); } template class has_plus_assign : public false_type {}; template class has_plus_assign()+=declval(),void(0))> : public true_type {}; template class has_minus_assign : public false_type {}; template class has_minus_assign()-=declval(),void(0))> : public true_type {}; template class has_mul_assign : public false_type {}; template class has_mul_assign()*=declval(),void(0))> : public true_type {}; template class has_div_assign : public false_type {}; template class has_div_assign()/=declval(),void(0))> : public true_type {}; template auto operator+=(T& a,const T& b) -> typename enable_if::value,T&>::type{ for(size_t i=0;i auto operator+(T a,const T& b) -> typename enable_if::value,T>::type{ return a+=b; } template auto operator-=(T& a,const T& b) -> typename enable_if::value,T&>::type{ for(size_t i=0;i auto operator-(T a,const T& b) -> typename enable_if::value,T>::type{ return a-=b; } template auto operator*=(T& a,const T& b) -> typename enable_if::value,T&>::type{ for(size_t i=0;i auto operator*(T a,const T& b) -> typename enable_if::value,T>::type{ return a*=b; } template auto operator/=(T& a,const T& b) -> typename enable_if::value,T&>::type{ for(size_t i=0;i auto operator/(T a,const T& b) -> typename enable_if::value,T>::type{ return a/=b; } template void Rev(T& a){ reverse(a.begin(),a.end());} template void Sort(T& a){ sort(a.begin(),a.end()); } template void RSort(T& a){ sort(a.rbegin(),a.rend()); } template T Reved(T a){ reverse(a.begin(),a.end()); return a; } template T Sorted(T a){ sort(a.begin(),a.end()); return a; } template T RSorted(T a){ sort(a.rbegin(),a.rend()); return a; } template T Sum(vector a){ return accumulate(a.begin(),a.end(),T(0)); } template T Max(vector a){ return *max_element(a.begin(),a.end()); } template T Min(vector a){ return *min_element(a.begin(),a.end()); } template void ChMax(T& a,T b){ a=max(a,b); } template void ChMin(T& a,T b){ a=min(a,b); } i64 Tr(i64 n){ return n*(n+1)/2; } i64 PopCnt(u64 k){ return __builtin_popcountll(k); } templateT Pow(T a,i64 n){ T res=1; while(n){ if(n&1){ res*=a; } a*=a; n/=2; } return res; } i64 Pow(i64 a,i64 n,i64 m){ i64 res=1; while(n){ if(n&1){ res=res*a%m; } a=a*a%m; n/=2; } return res; } template vector CoorComp(vector a){ Sort(a); a.erase(unique(a.begin(),a.end()),a.end()); return a; } template vector NaiveConv(vector f,vector g){ vector h(f.size()+g.size()-1); for(size_t i=0;i1){ i64 mid=(ok+ng)/2; (mid*mid<=n?ok:ng)=mid; } return ok; } i64 SqrtC(i64 n){ i64 ok=1e9+5,ng=0; while(std::abs(ok-ng)>1){ i64 mid=(ok+ng)/2; (mid*mid>=n?ok:ng)=mid; } return ok; } i64 FDiv(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a+b-1)/b; } return a/b; } i64 CDiv(i64 a,i64 b){ if(b<0){ a*=-1,b*=-1; } if(a<0){ return -(-a)/b; } return (a+b-1)/b; } vector LISSize(vector A){ int N=A.size(); vector dp(N+1,2e18),res(N+1); dp[0]=-1; for(int i=0;i) i64 CountInverse(vector A){ int N=A.size(); auto B=A; sort(B.begin(),B.end()); B.erase(unique(B.begin(),B.end()),B.end()); map mp; for(size_t i=0;i fwt(N); i64 ans=0; for(int i=0;i lpf; ESieve(int n_):n(n_),lpf(n_+1,-1){ for(i64 p=2;p<=n;++p){ if(lpf[p]!=-1){ continue; } for(i64 q=p;q<=n;q+=p){ if(lpf[q]==-1){ lpf[q]=p; } } } } vector> operator()(int m){ vector v; while(m!=1){ v.emplace_back(lpf[m]); m/=lpf[m]; } if(v.size()==0){ return {}; } vector> res; res.emplace_back(v[0],1); for(size_t i=1;i BFS(vector> G,int v){ int N=G.size(); vector dst(N,-1); queue q; dst[v]=0; q.emplace(v); while(q.size()){ int t=q.front(); q.pop(); for(auto u:G[t]){ if(dst[u]==-1){ dst[u]=dst[t]+1; q.emplace(u); } } } return dst; } vector Dijkstra(vector>>& G,int s){ int N=G.size(); vector dst(N,1e18); dst[s]=0; priority_queue,vector>,greater>> pq; pq.emplace(0,s); vector f(N); while(pq.size()){ auto [t,u]=pq.top(); pq.pop(); if(f[u]){ continue; } f[u]=1; for(auto [v,w]:G[u]){ if(dst[v]>dst[u]+w){ dst[v]=dst[u]+w; pq.emplace(dst[v],v); } } } return dst; } void SpreadGrid(vector& S,int h,int w,char c){ int H=S.size(),W=S[0].size(); auto res=MakeVec(h,""); for(int i=0;i> PrimeFact(i64 n){ vector> res; for(i64 i=2;i*i<=n;++i){ if(n%i!=0){ continue; } i64 ex=0; while(n%i==0){ ex++,n/=i; } res.emplace_back(i,ex); } if(n!=1){ res.emplace_back(n,1); } return res; } vector EnumDiv(i64 n){ vector res; for(i64 i=1;i*i<=n;++i){ if(n%i!=0){ continue; } res.emplace_back(i); if(i*i!=n){ res.emplace_back(n/i); } } sort(res.begin(),res.end()); return res; } template struct CSum2D{ int n,m; vector> a,c; CSum2D(vector> a_):n(a_.size()),m(a_[0].size()),a(a_){ auto b=MakeVec(n,m+1,0); for(int i=0;i(n+1,m+1,0); for(int j=0;j auto RunLenEnc(T a) -> vector>{ int n=a.size(); vector> res; typename decltype(a)::value_type now=a[0]; i64 l=1; for(int i=1;i struct Comb{ vector fac,ifac; Comb(int mx=3000000):fac(mx+1,1),ifac(mx+1,1){ for(int i=1;i<=mx;++i){ fac[i]=fac[i-1]*i; } ifac[mx]/=fac[mx]; for(int i=mx;i>0;--i){ ifac[i-1]=ifac[i]*i; } } T operator()(int n,int k){ if(n<0||k<0||n; Comb Cb; auto solve=[&](int a,int d){ if(a==0){ return mint(d?1:0); } mint ans=0; { int m=a-1; int g=m+d; ans+=Cb(m+g+1,m)*Cb(g,m); } { int m=a-2; int g=a+d; ans-=Cb(m+g+1,m)*Cb(g,a); } return ans; }; int T; Scan(T); while(T--){ int A,B,C,D; Scan(A,B,C,D); if(A!=B){ Print(0); continue; } Print(solve(A,D)*Cb(A+B+C+D,C)); } }