#include #define ll long long #define pb push_back #define R read() #define fi first #define se second using namespace std; inline int read(){ int x=0; char c=0; while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return x; } const int inf=0x3f3f3f3f,N=100005; const ll INF=0x3f3f3f3f3f3f3f3f,M=1000000007; int T,n,m,v; pair p[N]; ll ans; ll power(ll x,int y){ ll res=1; while(y){ if(y&1) res*=x,res%=M; x*=x,x%=M,y>>=1; } return res; } int main(){ freopen("assign.in","r",stdin); freopen("assign.out","w",stdout); T=R; while(T--){ n=R,m=R,v=R,ans=1; for(int i=1;i<=m;i++) p[i]={R,R}; sort(p+1,p+m+1); m=unique(p+1,p+m+1)-p-1; for(int i=2;i<=m;i++){ if(p[i].fi==p[i-1].fi){ puts("0"); goto out; } ans*=power(v,2*(p[i].fi-p[i-1].fi))-power(v,p[i].fi-p[i-1].fi-1)*(v-1)%M+M; ans%=M; } ans*=power(v,2*(p[1].fi-1)),ans%=M; ans*=power(v,2*(n-p[m].fi)),ans%=M; printf("%lld\n",ans); out:; } return 0; }