#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
const ll mod=1000000007;

int T;
ll n,m,v;
ll c[maxn],d[maxn];
ll x[maxn];

struct node{
	ll fi,se;
	bool operator < (const node &o){
		if(fi!=o.fi)return fi<o.fi;
		return se<o.se;
	}
	bool operator == (const node &o){
		return fi==o.fi&&se==o.se;
	}
};
//node Node(int r,int y){
//	node ret;
//	ret.fi=r;ret.se=y;
//	return ret;
//}

bool is_special_A(){
	if(n!=m)return 0;
	for(int i=1;i<=m;i++)if(c[i]!=i)return 0;
	return 1;
}

ll qpow(ll r,ll y){
	ll ret=1,tmp=r;
	while(y!=0){
		if(y%2==1){
			ret*=tmp;ret%=mod;
		}
		tmp=tmp*tmp%mod;y/=2;
	}
	return ret;
}
node a[maxn];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++){
			cin>>c[i]>>d[i];
		}
		ll ans=0;a[0].fi=0;
		if(is_special_A()){
			a[n].fi=0;
			for(int i=1;i<=n;i++)x[i]=d[i];
			ll s=0;
			for(int i=1;i<=n-1;i++){
				a[i].fi=x[i],a[i].se=x[i+1];
			}
			sort(a+1,a+n);
			for(int i=1;i<=n-1;){
				s+=(a[i].fi-a[i-1].fi-1)*v;
				for(int j=i;;j++){
					if(a[j+1].fi!=a[i].fi){
						if(a[j].se==a[i].se)s++;
						i=j+1;break;
					}
				}
			}
			s+=(v-a[n-1].fi)*v;
			ans=qpow(s,n-1);
			cout<<ans<<endl;
		}
		else cout<<0<<endl;
	}
}
//1
//7 7 4
//1 2 2 1 3 2 4 3 5 2 6 1 7 3
