#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pi=pair<int,int>;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define G(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define si(a) ((int)(a).size())
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define pb push_back
template<class T> int cmn(T &x,T y){return y<x?x=y,1:0;}
template<class T> int cmx(T &x,T y){return y>x?x=y,1:0;}

const int mod=1e9+7;
struct mi{
	int x;
	mi(int x=0):x(x){}
	mi &operator+=(mi a){if((x+=a.x)>=mod) x-=mod; return *this;} 
	mi &operator-=(mi a){if((x-=a.x)<0) x+=mod; return *this;} 
	mi &operator*=(mi a){x=(ll)x*a.x%mod; return *this;}
	friend mi operator+(mi a,mi b){return a+=b;}
	friend mi operator-(mi a,mi b){return a-=b;}
	friend mi operator*(mi a,mi b){return a*=b;}
	mi pow(ll b=mod-2){
		mi a=x,res=1;
		for(;b;b>>=1,a*=a) if(b&1) res*=a;
		return res;
	}
};

const int N=1e6+3;
int n,m,v,a[N];
mi dp[N][2];

struct mat:array<array<mi,2>,2>{
	mat(mi v=0){
		F(i,0,1) F(j,0,1) (*this)[i][j]=i==j?v:0; 
	}
};
mat operator*(const mat &a,const mat &b){
	mat res;
	F(i,0,1) F(j,0,1) F(k,0,1) res[i][j]+=a[i][k]*b[k][j];
	return res;
}
mat qp(mat a,ll b){
	mat res(1);
	for(;b;b>>=1,a=a*a) if(b&1) res=res*a;
	return res;
}

void run(){
	cin>>n>>m>>v;
	map<int,int> mp;
	int flg=0;
	F(i,1,m){
		int x,y;
		cin>>x>>y;
		if(mp.count(x)){
			if(mp[x]!=y) flg=1;
			i--;
			m--;
			continue;
		}
		mp[x]=y;
		a[i]=x;
	}
	if(flg){
		cout<<0<<'\n';
		return;
	}
	sort(a+1,a+m+1);
	mat dp;
	if(a[1]==1) dp[0][1]=1;
	else dp[0][0]=1;
	mat co;
	co[0][0]=mi(v)*v; co[0][1]=0;
	co[1][0]=mi(v-1)*v; co[1][1]=v;
	int las=1;
	F(i,1,m) if(a[i]!=1){
		dp=dp*qp(co,a[i]-las-1);
		dp[0][1]=dp[0][0]*v*v+dp[0][1]*(mi(v-1)*v+1);
		dp[0][0]=0;
		las=a[i];
	}
	dp=dp*qp(co,n-las);
	mi ans=dp[0][0]+dp[0][1];
	cout<<ans.x<<'\n';
}

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