#include <iostream>
#include <algorithm>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;
const ll maxn = 1e5+10,mod=1e9+7; 
ll T,n,m,v;
pair<ll,ll> lim[maxn];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--){
		memset(lim,0,sizeof(lim));
		cin>>n>>m>>v;
		for(ll i=1;i<=m;i++){
			cin>>lim[i].first>>lim[i].second;
		}
		sort(lim+1,lim+1+m);
		ll siz=unique(lim+1,lim+1+m)-lim-1;
		ll lp=0,p=1,s=0,ans=1,lst=0;
		for(ll i=1;i<=siz;i++){
			if(lim[i].first==lim[p].first) continue;
			else{
				if(lim[p].first-lim[lp].first==1){
					ans*=(((v-i+p)*(v-p+lp))%mod)+(((v-p+lp)*v)%mod);
				}
				else{
					ans*=((v-p+lp)*v)%mod;
				}
				lst++;
				lp=p;
				p=i;
			}
		}
		if(lim[lp].first!=0){
			if(lim[p].first-lim[lp].first==1) ans*=(((v-siz+p)*(v-p+lp))%mod)+(((v-p+lp)*v)%mod);
			else ans*=((v-p+lp)*v)%mod;	
		}
		if(lim[p].first!=n){
			ans*=(v-siz+p)%mod;
			lst++;
		}
		ans*=(((n-lst)%mod)*(v%mod))%mod;
		if(ans==1) ans = 0;
		cout<<ans<<endl;
	}
	return 0;
}
