#include<bits/stdc++.h>
using namespace std;

struct Struct_IO {
	#define FileNaME "assign"
	Struct_IO(){
		freopen(FileNaME ".in", "r", stdin);
		freopen(FileNaME ".out", "w", stdout);
	}
	~Struct_IO(){
		fclose(stdin);
		fclose(stdout);
	}
} io_io;

long long ans;

void clear(){
	ans=1;
}

#define M 100005 
#define MOD 1000000007 
int m,n,v;
struct YYXZ {
	int c,d;
	bool operator<(YYXZ y){
		return c < y.c;
	}
} yyxz[M];

void input(){
	cin>>n>>m>>v;
	v%=MOD;
	for(int i=0; i<m; i++) {
		cin>>yyxz[i].c>>yyxz[i].d;
	}
	sort(yyxz, yyxz+m);
}

bool delre(){
	int i,p;
	for(i=0, p=0; i<m; i++, p++){
		if(yyxz[i].c==yyxz[i-1].c&&yyxz[i].d!=yyxz[i-1].d)return 1;
		if(yyxz[i].c==yyxz[i-1].c){
			p--;
		}
		yyxz[p] = yyxz[i];
	}
	m=p;
	return 0;
}

long long qsm(long long x, int a){
	long long r = 1;
	x%=MOD;
	while(a){
		if(a&1){
			r*=x;
			r%=MOD;
		}
		x*=x;
		x%=MOD;
		a>>=1;
	}
	return r;
}
void ad(long long x){
	ans*=x;
	ans%=MOD;
}


long long AA,BB;
void add(int l, int r){//[l,r]
	int len = r - l + 1;
	if(len<=0) return;
	ad(qsm(BB,len));
}

void run(){
	clear();
	input();
	if(delre()){
		cout<<0<<endl;return;
	}
	
	long long MMM = (v-1)*v;MMM%=MOD;
	AA = MMM + 1;AA%=MOD;
	BB = MMM + v;BB%=MOD;
	
	if(yyxz[0].c==1){}else{
		//ad(v);
		add(2, yyxz[0].c-1);
		ad(BB);
	}
	/*
	for(int i=2; i<=n; i++){
		if(p<m&&yyxz[p].c==i){
			ad(AA);
			p++;
		}else{
			ad(BB);
		}
	}*/
	for(int i=1; i<m; i++){
		add(yyxz[i-1].c+1, yyxz[i].c-1);
		if(yyxz[i-1].c+1==yyxz[i].c){
			ad(AA);
		}
		else ad(BB);
	}
	add(yyxz[m-1].c+1, n);
	
	//for(int i=0; i<m; i++){
	//	printf("%d:%d ", yyxz[i].c, yyxz[i].d);
	//}
	//cout<<MMM<< " "<<AA<< " "<<BB<< " ";
	cout<<ans<<endl;
}

int main(){
	int t;
	cin>>t;
	while(t--){
		run();
	}
	return 0;
}
