#include using namespace std; #define int long long const int M=1e5+5,mod=1e9+7; int read(){ int num=0,typ=1,c=getchar(); while('0'>c||c>'9'){ if(c=='-') typ=-1; c=getchar(); }while('0'<=c&&c<='9'){ num=num*10+c-48; c=getchar(); }return num*typ; } int t; int n,m,v,ans,res[M]; int qpow(int x,int y){ int ans=1; while(y){ if(y&1) (ans*=x)%=mod; (x*=x)%=mod; y>>=1; }return ans; } pairp[M]; signed main(){ freopen("assign.in","r",stdin); freopen("assign.out","w",stdout); for(t=read();t;t--){ n=read();m=read();v=read(); for(int i=1;i<=m;i++){ p[i].first=read(); p[i].second=read(); } sort(p+1,p+m+1); m=unique(p+1,p+m+1)-p-1; res[m]=0; ans=qpow(v*v%mod,n-p[m].first); for(int i=m-1;i>=1;i--){ if(p[i].first==p[i+1].first){ ans=0; break; } res[i]=(qpow(v*v%mod,p[i+1].first-p[i].first)-(qpow(v,p[i+1].first-p[i].first-1)*(v-1))%mod+mod)%mod; (ans*=res[i])%=mod; } (ans*=qpow(v*v%mod,p[1].first-1))%=mod; printf("%lld\n",ans); } return 0; }