#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10,P=1e9+7;
int m,n,o,a[N],a1[N],b[N],b1[N];
long long v;
long long power(int x)
{
	int z=x; long long ans=1,sum=v;
	while(z){
		if(z&1) ans=ans*sum%P; 
		sum=sum*sum%P; z>>=1;
	}
	return ans;
}
void qsort(int l,int r)
{
	if(l==r) return ;
	int mid=(l+r)>>1;
	qsort(l,mid); qsort(mid+1,r);
	int t=mid,q=l-1;
	for(int i=l;i<=mid;i++){
		while(t<r&&a[t+1]<=a[i]) t++,a1[++q]=a[t],b1[q]=b[t];
		a1[++q]=a[i]; b1[q]=b[i];
	}
	while(t<r) t++,a1[++q]=a[t],b1[q]=b[t];
	for(int i=l;i<=r;i++){
		a[i]=a1[i],b[i]=b1[i];
	}
	return ;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&o);
	while(o--){
		scanf("%d%d%lld",&m,&n,&v);
		for(int i=1;i<=n;i++){
			scanf("%d%d",&a[i],&b[i]);
		}
		if(n!=1) qsort(1,n);
		bool flag=true;
		for(int i=1;i<=n;i++){
			if(a[i]==a[i-1]&&b[i-1]!=b[i]){
				flag=false; break;
			}
		}
		if(!flag){
			printf("0\n"); continue ;
		}
		long long ans=power(2*(a[1]-1));
		for(int i=2;i<=n;i++){
			if(a[i]==a[i-1]) continue ;
			ans=ans*(power(2*(a[i]-a[i-1]))-power(a[i]-a[i-1]-1)*(v-1)%P+P)%P;
		}
		ans=ans*(power(2*(m-a[n])))%P; 
		printf("%lld\n",ans);
	}
	return 0;
}
