fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #define ll long long int
  5. #define nl '\n'
  6. #define rep(i,a,b) for(int i=a;i<=b;++i)
  7. #define all(a) a.begin(),a.end()
  8. const ll N=4e6+9;
  9. const ll mod=1e9+7;
  10.  
  11. ll powerk(ll x, ll y);
  12.  
  13. ll a[N];
  14.  
  15. void pre()
  16. {
  17. a[0]=1;
  18. a[1]=1;
  19. rep(i,2,4000006)
  20. {
  21. a[i] = (a[i-1]*i)%mod;
  22. }
  23. }
  24.  
  25. int main() {
  26. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  27. ll n;
  28. pre();
  29. cin>>n;
  30. while(n--)
  31. {
  32. ll aa,b,c,d;
  33. cin>>aa>>b>>c>>d;
  34. ll x = abs(c-aa)+1;
  35. ll y = abs(d-b)+1;
  36.  
  37. cout<< (a[x+y-2]*(powerk((a[x-1]*a[y-1])%mod,mod-2)))%mod<<nl;
  38. }
  39. }
  40.  
  41. ll powerk(ll x, ll y)
  42. {
  43. if(y==0)return 1;
  44. if(y==1)return x%mod;
  45. if(y&1)
  46. return ((powerk((x*x)%mod, y/2)%mod)*x)%mod;
  47. else return powerk((x*x)%mod,y/2)%mod;
  48. }
Runtime error #stdin #stdout 0.02s 34380KB
stdin
Standard input is empty
stdout
Standard output is empty