#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a struct Mint{ static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v constexpr T Mint::mod; template ostream& operator<<(ostream &os,Mint m){os<; const int MAX = 20002; M dp[5*5*5*5][MAX]; int win[5*5*5*5]={}; int calc(int a,int b,int c,int d){ return (((a*5+b)*5+c)*5+d); } using P = pair; vector

vp[5*5]; void init(){ for(int j=0;j<5*5*5*5;j++){ int a=(j/125)%5; int b=(j/25)%5; int c=(j/5)%5; int d=(j/1)%5; if(a==0&&b==0) continue; if(c==0&&d==0) continue; for(int k=0;k<4;k++){ int nc=c,nd=d; int add=(~k&1?a:b); (k/2?nc:nd)+=add; (k/2?nc:nd)%=5; if(nc==0&&nd==0) win[j]=1; } } for(int j=0;j<5*5*5*5;j++){ int a=(j/125)%5; int b=(j/25)%5; int c=(j/5)%5; int d=(j/1)%5; if(a==0&&b==0) continue; if(c==0&&d==0) continue; if((a+b)%5!=(c+d)%5) continue; if(P(a,b)==P(c,d)) continue; if(P(a,b)==P(d,c)) continue; vp[a*5+b].emplace_back(c,d); //cout<>n>>k; int l1,r1,l2,r2; cin>>l1>>r1>>l2>>r2; dp[calc(l1,r1,l2,r2)][0]=1; M ans{0}; for(int i=0;i