#include <cstdio>
#include <algorithm>
#define int long long

using namespace std;

void re(int &x){
	x=0;int c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
}

const int mod=1e9+7;

int v;int fp(int p){
	int r=1,x=v;while(p){
		if(p&1) (r*=x)%=mod;
		(x*=x)%=mod;p>>=1;
	}return r;
}

struct asn{
	int p,x;bool operator<(const asn &t)const{return p<t.p;}
	bool operator==(const asn &t)const{return p==t.p;}
}a[114514];

signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;re(T);while(T--){
		int n,m;re(n);re(m);re(v);
		for(int i=1;i<=m;++i) re(a[i].p),re(a[i].x);
		sort(a+1,a+m+1);bool flg=0;
		for(int i=1;i<=m;++i) if(a[i].p==a[i-1].p&&a[i].x!=a[i-1].x) flg=1;
		if(flg){puts("0");continue;}
		m=unique(a+1,a+m+1)-a-1;
		int ans=fp(2*(a[1].p-1))*fp(2*(n-a[m].p))%mod;
		for(int i=1;i<m;++i) (ans*=fp(2*(a[i+1].p-a[i].p))-(v-1)*fp(a[i+1].p-a[i].p-1)%mod+mod)%=mod;
		printf("%lld\n",ans);
	}
}
