#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define ve vector<ll>
#define pb push_back
#define fi first
#define se second
#define mid (l+r>>1)
using namespace std;
const ll N=2e5+2,P=1e9+7;
ll T,n,m,v;
pii c[N];
struct mat{
	ll a[2][2];
	mat(ll X=0,ll Y=0,ll Z=0,ll W=0){
		a[0][0]=X,a[0][1]=Y,a[1][0]=Z,a[1][1]=W;
	}
	ll*operator[](ll x){return a[x];}
	mat operator*(mat x){
		mat y;
		for(ll i=0;i<2;i++)
			for(ll j=0;j<2;j++)
				for(ll k=0;k<2;k++)
					(y[i][k]+=a[i][j]*x[j][k])%=P;
		return y;
	}
	mat ksm(ll y){
		return y?(*this**this).ksm(y>>1)*(y&1?*this:mat(1,0,0,1)):mat(1,0,0,1);
	}
}F,G;
void slv(){
	cin>>n>>m>>v;
	for(ll i=1;i<=m;i++)cin>>c[i].fi>>c[i].se;
	sort(c+1,c+m+1);
	mat X(0,1,0,0);
	F=mat(v,(v*v-v)%P,0,v*v%P);
	G=mat((v*v-v+1)%P,0,v*v%P,0);
	c[0].fi=1;
	for(ll i=1;i<=m;i++){
		if(i>1&&c[i].fi==c[i-1].fi){
			if(c[i].se!=c[i-1].se)return cout<<"0\n",void();
			continue;
		}
		if(i==1&&c[i].fi==1)X=mat(1,0,0,0);
		else
			X=X*F.ksm(c[i].fi-c[i-1].fi-1)*G;
	}
	X=X*F.ksm(n-c[m].fi);
	cout<<(X[0][0]+X[0][1])%P<<'\n';
}
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--)slv();
	return 0;
}