# include<iostream>
# include<cstdio>
# include<algorithm>
using namespace std;
# define ll long long

const int M=1e5+2;
const ll mod=1e9+7;
int t,n,m,g;
ll v,ans,tmp;

struct limit{
	int c;
	ll d;
	void in(){
		cin>>c>>d;
	}
}a[M];

bool cmp(limit x,limit y){
	return (x.c==y.c?x.d<y.d:x.c<y.c);
}

ll f(ll x){
	return (x%mod+mod)%mod;
}

ll pow(ll x,int y){
	if(x==1||x==0||y==1) return x;
	if(y==0) return 1;
	ll t=pow(x,y/2)%mod;
	if(y%2) return t*t%mod*x%mod;
	else return t*t%mod;
}

void solve(){
	cin>>n>>m>>v;
	for(int i=1;i<=m;++i) a[i].in();
	if(v==1){
		cout<<1<<endl;
		return;
	}
	sort(a+1,a+m+1,cmp);
	ans=1;
	for(int i=0;i<=m;++i){
		if(a[i].d>v){
			ans=-1;
			break;
		}
		if(i>0&&i<m&&a[i].c==a[i+1].c){
			if(a[i].d==a[i+1].d) continue;
			else{
				ans=-1;
				break;
			}
		}
		if(i==0){
			if(a[1].c==1) continue;
			g=a[1].c-1;
			tmp=pow(v%mod,2*g);
		}
		else if(i==m){
			if(a[m].c==n) continue;
			g=n-a[m].c;
			tmp=pow(v%mod,2*g);
		}
		else{
			g=a[i+1].c-a[i].c;
			tmp=f(pow(v%mod,2*g)-pow(v%mod,g-1)*(v-1)%mod);
		}
		ans=ans*tmp%mod;
	}
	if(ans==-1) cout<<0<<endl;
	else cout<<ans%mod<<endl;
}

int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--) solve();
	return 0;
}
