#include<bits/stdc++.h>
using namespace std;
struct lk{
	int x,z;
};
int q,w,e,r;
lk t[100001];
long long y,u[100001];
bool lkj(lk a,lk s){
	return a.x<s.x;
}
int lkjh(int a){
	if(u[a]==0){
		int s=a/2;
		u[a]=(lkjh(s)*lkjh(a-s))%1000000007;
	}
	return u[a];
}
int main(){//y
//	freopen("assign.in","r",stdin);
//	freopen("assign.out","w",stdout);
	cin>>q;
	for(int c=1;c<=q;c++){
		memset(u,0,sizeof(u));
		cin>>w>>e>>r;
		for(int v=1;v<=e;v++){
			cin>>t[v].x>>t[v].z;
		}
		y=1;
		sort(t+1,t+1+e,lkj);
		for(int v=1;v<e;v++){
			if(t[v].x==t[v+1].x){
				y=0;
				break;
			}
			if(t[v].x+1!=t[v+1].x){
				w++;
			}else{
				y=(y*((r*(r-1)+1)%1000000007))%1000000007;
			}
		}
		if(y==0){
			cout<<y<<endl;
			continue;
		}
		u[1]=(r*r)%1000000007;
		u[0]=1;
		y=lkjh(w-e);
		cout<<y<<endl;
	}
	return 0;
}
