#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i) 
#define fd(i,a,b) for(int i=(a);i>=(b);--i) 
#define fu(i,a,b) for(int i=(a);i<(b);++i)
#define ll long long 
using namespace std;
const int N=1e5+5,mo=1e9+7;
int T,n,m;
struct nd{int c,d;};
bool operator <(nd x,nd y){return x.c<y.c||(x.c==y.c&&x.d<y.d);}
nd a[N];
ll anss[N],hf[N],ans,v;
inline ll power(ll x,ll y)
{
	ll z=1;
	while(y)
	{
		if(y&1)z=z*x%mo;
		x=x*x%mo;y>>=1;
	}
	return z;
}
int main()
{
	freopen("assign.in","r",stdin); 
	freopen("assign.out","w",stdout); 
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%lld",&n,&m,&v);
		fo(i,1,m)scanf("%d%d",&a[i].c,&a[i].d);
		sort(a+1,a+m+1);int can=1;
		fo(i,2,m)if(a[i].c==a[i-1].c&&a[i].d!=a[i-1].d){can=0;break;}
		if(!can)printf("0\n");
		else
		{
			hf[1]=1;
			fo(i,2,m)
			{
				if(a[i].c==a[i-1].c)
				{
					anss[i]=anss[i-1];hf[i]=hf[i-1];
					continue;
				}
				anss[i]=hf[i-1]*power(v,(ll)a[i].c-a[i-1].c-1)%mo*(v-1)%mo;
				hf[i]=(hf[i-1]*power(v,2ll*(a[i].c-a[i-1].c))%mo+mo-anss[i])%mo;
			}
			printf("%lld\n",hf[m]*power(v,2ll*(a[1].c-1+n-a[m].c))%mo);
		}
	}
	return 0;
}
