#include #define ll long long #define eb emplace_back #define mk make_pair #define N 100009 #define nc() getchar() using namespace std; inline int rd(){int ans=0;char ch=nc();while(ch<'0'||ch>'9')ch=nc();while(ch>='0'&&ch<='9')ans=ans*10+ch-'0',ch=nc();return ans;} const int mod=1e9+7; int ksm(int a,int b){ int ans=1; while(b){ if(b&1)ans=1ll*ans*a%mod; a=1ll*a*a%mod,b>>=1; } return ans; } int t,n,m,v;pairp[N]; int f[2],g[2][2],h[2][2]; inline void mul(int a[2][2],int b[2][2],int c[2][2]){ static int nw[2][2]; nw[0][0]=(1ll*a[0][0]*b[0][0]+1ll*a[0][1]*b[1][0])%mod; nw[0][1]=(1ll*a[0][0]*b[0][1]+1ll*a[0][1]*b[1][1])%mod; nw[1][0]=(1ll*a[1][0]*b[0][0]+1ll*a[1][1]*b[1][0])%mod; nw[1][1]=(1ll*a[1][0]*b[0][1]+1ll*a[1][1]*b[1][1])%mod; c[0][0]=nw[0][0],c[0][1]=nw[0][1],c[1][0]=nw[1][0],c[1][1]=nw[1][1]; } inline void mul(int a[2],int b[2][2],int c[2]){ static int nw[2]; nw[0]=(1ll*a[0]*b[0][0]+1ll*a[1]*b[1][0])%mod; nw[1]=(1ll*a[0]*b[0][1]+1ll*a[1]*b[1][1])%mod; c[0]=nw[0],c[1]=nw[1]; } int main(){ freopen("assign.in","r",stdin); freopen("assign.out","w",stdout); t=rd(); while(t--){ n=rd(),m=rd(),v=rd(); for(int i=1;i<=m;i++)p[i].first=rd(),p[i].second=rd(); sort(p+1,p+m+1);bool flag=0,lim1=0,limn=0; for(int i=1;i>=1; } mul(f,ans,f),mul(f,h,f); lst=p[i].first; } if(lst>=1; } mul(f,ans,f); lst=n-1; } int ans=0; if(!limn)ans=(1ll*f[0]+1ll*f[1])*v%mod; else ans=(1ll*f[0]*v%mod+f[1])%mod; printf("%d\n",ans); } return 0; }