#include<bits/stdc++.h>
using namespace std;
namespace IO{
	template<class T> inline void read(T &x){
		char ch=getchar(),fushu=0; x=0;
		while(ch<'0'||ch>'9'){
			if(ch=='-')fushu=1;
			ch=getchar();
		}
		while(ch>='0'&&ch<='9')x=x*10+(ch^48),ch=getchar();
		if(fushu)x=-x;
	}
	char p[205];
	template<class T> inline void write(T x){
		if(x<0)putchar('-'),x=-x;
		if(!x)putchar('0');
		int t=0;
		while(x)p[++t]=(x%10)^48,x/=10;
		while(t)putchar(p[t--]);
	}
}
using IO::read;
using IO::write;
#define ll long long
#define ull unsigned long long
#define ld long double
#define it128 __int128
#define fo(i,l,r) for(int i=(l);i<=(r);++i)
#define fd(i,r,l) for(int i=(r);i>=(l);--i)
#define fu(i,l,r) for(int i=(l);i<(r);++i)
int T;
int n,m,V;
const int mod=1e9+7;
const int N=1e5+5;
pair<int,int> a[N];
int pow1(int x,int y){
	int res=1;
	for(;y;y>>=1,x=(ll)x*x%mod)if(y&1)res=(ll)res*x%mod;
	return res;
}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	read(T);
	while(T--){
		read(n),read(m),read(V);
		fo(i,1,m){
			read(a[i].first),read(a[i].second);
		}
		sort(a+1,a+1+m);
		int no=0;
		fo(i,1,m-1){
			if(a[i].first==a[i+1].first&&a[i].second!=a[i+1].second)no=1;
		}
		if(no){
			write(0),putchar('\n');
			continue;
		}
		m=unique(a+1,a+1+m)-a-1;
		int ans=1;
		fo(i,1,m-1){
			int cnt=a[i+1].first-a[i].first;
			ans=(ll)ans*(pow1(V,2*cnt)-(ll)pow1(V,cnt-1)*(V-1)%mod)%mod;
		}
		ans=(ll)ans*pow1(V,(2ll*(a[1].first-1)+2ll*(n-a[m].first))%(mod-1))%mod;
		write((ans+mod)%mod),putchar('\n');
	}
	return 0;
}

