#include<bits/stdc++.h>
using namespace std;
/*long long read()
{
	long long f=1,x=0;
	char a=getchar();
	while(a<'0'||a>'9')
	{
		if(a=='-') f=-1;
		a=getchar();
	}
	while(a>='0'&&a<='9')
	{
		x=x*10+a-48;
		a=getchar();
	}
	return f*x;
}*/
const long long N=1e5+10,mod=1e9+7;
long long n,m,v,a[N][2],x[N],b[N],k,f[N],t;
long long jc(long long a,long long b)
{
	long long s=1;
	while(a)
	{
		if(a&1) s=s*b%mod;
		b=b*b%mod;
		a=a/2;
	}
	return s;
}
int main()
{
    freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
    scanf("%lld",&t); 
    while(t--)
    {
    	scanf("%lld%lld%lld",&n,&m,&v);k=0;
        for(int i=1;i<=m;i++)
	    {
		    scanf("%lld%lld",&a[i][0],&a[i][1]);
		    x[i]=a[i][0];b[i]=0;
	    } 
	    sort(x+1,x+m+1);
	    for(int i=1;i<=m;i++)
	    {
		    int to=lower_bound(x+1,x+m+1,a[i][0])-x;
		    if(b[to]!=0&&b[to]!=a[i][1])
		    {
	 	        k=1;
	 	        break;
	        }
		    b[to]=a[i][1];
		    //cout<<x[i]<<" ";
	    }
	    if(k)
	    {
	    	printf("0\n");
	    	continue;
		}
	    f[m]=jc((n-x[m])*2,v);
	    for(int i=m-1;i>=1;i--)
	    if(x[i]!=x[i+1])
		 f[i]=f[i+1]*((jc((x[i+1]-x[i])*2,v)+mod-((v-1)*jc(x[i+1]-x[i]-1,v))%mod)%mod)%mod;
		else 
		 f[i]=f[i+1];
	    f[1]=f[1]*jc((x[1]-1)*2,v)%mod;
	    printf("%lld\n",f[1]);
	}
    
	return 0;
} 
