1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxm=3e5+10,mod=1000000007; 4 const int maxn=4e3+10; 5 typedef long long ll; 6 7 ll fac[maxm],inv[maxm]; 8 ll fpm(ll a,ll b){ 9 ll ret=1; 10 for(;b;b>>=1,a=a*a%mod) 11 if(b&1)ret=ret*a%mod; 12 return ret; 13 } 14 void init(){ 15 fac[0]=1; 16 for(int i=1;i<maxm;++i) 17 fac[i]=fac[i-1]*i%mod; 18 inv[maxm-1]=fpm(fac[maxm-1],mod-2); 19 for(int i=maxm-1;i;--i) 20 inv[i-1]=inv[i]*i%mod; 21 } 22 ll Inv(ll x){ 23 ll ret; 24 if(x==0)return 0; 25 else if(x<0){ 26 x=-x; 27 ret=fac[x-1]*inv[x]%mod; 28 ret=mod-ret; 29 }else{ 30 ret=fac[x-1]*inv[x]%mod; 31 } 32 return ret; 33 } 34 int n,x[maxn],y[maxn]; 35 ll f[maxn][maxn]; 36 void input(){ 37 38 for(int i=1;i<=n;++i){ 39 scanf("%d%d",x+i,y+i); 40 f[0][i]=y[i]; 41 } 42 for(int i=1;i<=n;++i) 43 for(int j=1;j+i<=n;++j){ 44 f[i][j]=(f[i-1][j+1]-f[i-1][j]+mod)%mod; 45 f[i][j]=f[i][j]*Inv(x[i+j]-x[j])%mod; 46 f[i][j]%=mod;//len i from j 47 } 48 } 49 50 ll ans,cur,tmp; 51 void solve(){ 52 int m=0;scanf("%d",&m); 53 for(int l,r,q;m--;){ 54 scanf("%d%d%d",&l,&r,&q); 55 cur=1;ans=0; 56 for(int i=0;i<=r-l;++i){ 57 (ans+=f[i][l]*cur%mod)%=mod; 58 tmp=(q-x[l+i]+mod)%mod; 59 cur=cur*tmp%mod; 60 } 61 printf("%lld ",ans); 62 //if(m)puts(""); 63 } 64 } 65 int main(){ 66 init(); 67 for(;~scanf("%d",&n);){ 68 input(); 69 solve(); 70 } 71 return 0; 72 }