#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll s=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		s=s*10+(ch-'0');
		ch=getchar();
	}
	return s*f;
}
#define vector basic_string
#define pii array<ll,2>
ll T,n,m,v,ans;
vector<pii>c;
const ll mod=1e9+7;
ll power(ll a,ll b){
	b%=(mod-1),a%=mod;
	ll ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod,b>>=1;
	}
	return ans;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	T=read();
	while(T--){
		n=read(),m=read(),v=read();
		c.clear();
		if(!m){
			printf("%lld\n",power(v,(n-1)*2));
			continue;
		}
		for(ll i=1;i<=m;i++)
			c+={{read(),read()}};
		sort(c.begin(),c.end());
		c.erase(unique(c.begin(),c.end()),c.end());
		for(ll i=0;i+1<c.size();i++) if(c[i][0]==c[i+1][0]){puts("0");goto nxt;}
		ans=power(v,((c[0][0]-1)+(n-c.back()[0]))*2);
		for(ll i=0,res;i+1<c.size();i++){
			res=power(v,(c[i+1][0]-c[i][0])*2);
			res=(res+mod-power(v,c[i+1][0]-c[i][0]-1)*(v-1)%mod)%mod;
//			printf("mul %lld %lld\n",res,i+1);
			ans=ans*res%mod;
//			printf("%lld\n",ans);
		}
		printf("%lld\n",ans);
		nxt:;
	}
	return 0;
}

