#include <bits/stdc++.h>
using namespace std;
#define ll long long
int t;
ll n,m,v;
pair<int,int> a[100005];
vector<int> s;
const ll mod=1e9+7;

ll fpow(ll a,ll b){
	ll ans=1,x=a;
	while(b){
		if(b&1)ans=(ans*x)%mod;
		x=(x*x)%mod;
		b>>=1;
	}
	return ans;
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin >> t;
	while(t--){
		cin >> n >> m >> v;
		memset(a,0,sizeof(a));
		for(int i=1;i<=m;i++){
			cin >> a[i].first >> a[i].second;
		}
		sort(a+1,a+1+m);
		ll ans=1;
		bool flag=1;
		if(a[1].first!=1)ans=(ans*fpow(v*v%mod,(a[1].first-1))%mod);
		for(int i=2;i<=m;i++){
			if(a[i].first==a[i-1].first&&a[i].second!=a[i-1].second)flag=0;
			if(a[i].first==a[i-1].first)continue;
			if(a[i].first-a[i-1].first==1)ans=(((v-1)*v%mod+1)*ans%mod)%mod;
			else ans=(fpow(v*(v)%mod,(a[i].first-a[i-1].first)%mod)%mod*ans)%mod;
		}
		if(n!=a[m].first)ans=(fpow(v*v%mod,(n-a[m].first)%mod)*ans)%mod;
		if(!flag)cout<<0<<endl; 
		else cout<<ans<<endl;
	}
	return 0;
}
/*
1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2
*/
