#include<bits/stdc++.h>
using namespace std;
const int P=1e9+7;
long long T;
long long n,m,v;
struct M{
	long long c,d;
	bool operator<(const M &a)const{
		return c<a.c;
	}
	bool operator==(const M &a)const{
		return c==a.c&&d==a.d;
	}
};
vector<M> num;
long long faster_pow(long long num){
	if(num==0){
		return 1;
	}if(num==1){
		return v;
	}
	long long tmp=(faster_pow(num/2)+P)%P;
	return (1ll*tmp*tmp%P*(num%2==1?v:1)+P)%P;
}
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--){
		long long ans=1;
		num.erase(num.begin(),num.end());
		cin>>n>>m>>v;
		for(int i=1,c,d;i<=m;i++){
			cin>>c>>d;
			num.push_back((M){c,d});
		}
		sort(num.begin(),num.end());
		num.erase(unique(num.begin(),num.end()),num.end());
		for(int i=1;i<num.size();i++){
			if(num[i].c==num[i-1].c&&num[i].d!=num[i-1].d){
				ans=0;
				break;
			}
			int tmp=num[i].c-num[i-1].c-1;
			int a=faster_pow(2*tmp+2),b=faster_pow(tmp+1),c=faster_pow(tmp);
			ans=(ans*(a-b+c)+P)%P;
		}
		if(num[0].c>1&&ans)ans=(ans*faster_pow(num[0].c*2-2)+P)%P;
		if(num[num.size()-1].c<n&&ans)ans=(ans*faster_pow(n*2-num[num.size()-1].c*2)+P)%P;
		cout<<(ans+P)%P<<"\n";
	}
	return 0;
}
