#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;
const int N=1e6+5,mod=1e9+7;
ll T,n,m,u,k,p,ans;
ll x[N];
int main(){
	freopen("assign.in" ,"r",stdin );
	freopen("assign.out","w",stdout);
	scanf("%lld",&T);
	while(T--){
		ans=1;
		memset(x,-1,sizeof x);
		scanf("%lld%lld%lld",&n,&m,&u);
		for (int i=1;i<=m;i++){
			scanf("%lld%ld",&k,&p);
			if(x[k]!=p&&x[k]!=-1)ans=0;
			x[k]=p;
		}
		for (int i=1;i<n;i++){
			if(x[i]!=-1&&x[i+1]!=-1){
				ans=(u*u%mod-u%mod+1)%mod*ans%mod;
			}else if(x[i]==-1||x[i+1]==-1){
				ans=u*u%mod*ans%mod;
			}
		}
		printf("%lld\n",ans);
	}
}
