#include<bits/stdc++.h>
#define int long long
#define mode 1000000007
using namespace std;
int t,n,m,v,s,c[100100],d[100100],a[100100],q[100100],l,num;
map<int,int>p;
struct abc
{
	int c,d;
}w[100100];
inline bool cmp(abc x,abc y)
{
	return x.c<y.c;
}
inline int quick_pow(int x,int y)
{
	if(y==0) return 1;
	int t=quick_pow(x,y>>1)%mode;
	if(y&1) return t*t%mode*x%mode;
	return t*t%mode;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld %lld %lld",&n,&m,&v);
		s=1;
		l=num=0;
		for(int i=1;i<=m;i++) scanf("%lld %lld",&w[i].c,&w[i].d);
		sort(w+1,w+m+1,cmp);
		for(int i=1;i<=m;i++) if(w[i].c==w[i-1].c&&w[i].d!=w[i-1].d) s=0;
		if(w[1].c>1) s*=quick_pow(v*v%mode,w[1].c-1);
		s%=mode;
		for(int i=2;i<m;i++)
		{
			if(w[i].c==w[i-1].c+1) s*=((v-1)*v+1)%mode;
			else s*=quick_pow(v*v%mode,w[i].c-w[i-1].c);
			s%=mode;
		}
		if(w[m].c<n) s*=quick_pow(v*v%mode,n-w[m].c);
		if(m==2)
		{
			if(w[2].c==w[1].c+1) s*=((v-1)*v+1)%mode;
			else s*=quick_pow(v*v%mode,w[2].c-w[1].c);
		}
		s%=mode;
		printf("%lld\n",s);
	}
	return 0;
}
