#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int maxn=1e5+5,mod=1e9+7;
int t;
ll n,v;
int m;
ll f[maxn];
struct xz
{
	ll c,d;
}q[maxn];
bool cmp(xz x,xz y)
{
	return x.c>y.c;
}
ll po(ll x,int n)
{
	ll tmp=1;
	while(n)
	{
		if(n&1)tmp=tmp*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return tmp;
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%d%lld",&n,&m,&v);
		memset(f,0,sizeof(f));
		for(int i=1;i<=m;i++)
		{
			scanf("%lld%lld",&q[i].c,&q[i].d);
		}
		sort(q+1,q+m+1,cmp);
		int o=1;
		if(q[1].c==n)
		{
			f[1]=1;
			o++;
		}
		q[0].c=n;
		f[0]=1;
		for(int i=o;i<=m;i++)
		{
			if(q[i].c==q[i-1].c)
			{
				if(q[i].d!=q[i-1].d)
				{
					f[m]=0;
					break;
				}
				else 
				{
					f[i]=f[i-1];
					continue;
				}
			}
			ll len=q[i-1].c-q[i].c;
			ll las=1;
			if(i==1)las=v;
			f[i]=((po(v,2*len)-po(v,len))%mod+po(v,len-1)*las%mod)*f[i-1]%mod;
		}
		f[m]=(f[m]%mod+mod)%mod;
		cout<<f[m]*po(v,2*(q[m].c-1))%mod<<"\n";
	}
	return 0;
}
