#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll N=100005,mod=1e9+7;
ll T,n,m,V;
ll f[N];
struct node{
	ll pos,val;
}a[N];

ll power(ll x,ll p)
{
	ll re=1;
	while(p)
	{
		if(p&1) re=re*x%mod;
		x=x*x%mod;
		p>>=1;
	}
	return re;
}

int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%lld%lld",&n,&m,&V);
		for(int i=1;i<=m;i++)
		{
			scanf("%lld%lld",&a[i].pos,&a[i].val);
		}
		
		sort(a+1,a+1+m,[](node x,node y){
			return x.pos<y.pos;
		});
		
		int flag=0;
		for(int i=2;i<=m;i++)
		{
			if(a[i].pos==a[i-1].pos && a[i].val!=a[i-1].val)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			puts("0");
			continue;
		}
		
		ll v2=V*V%mod;
		f[1]=power(v2,a[1].pos-1);
		for(int i=1;i<m;i++)
		{
			if(a[i].pos==a[i+1].pos)
			{
				f[i+1]=f[i];
				continue;
			}
			
			ll len=a[i+1].pos-a[i].pos-1;
			f[i+1]=(power(v2,len+1)-power(V,len)*(V-1)%mod+mod)%mod*f[i]%mod;
		}
		
		if(a[m].pos!=n) 
			f[m]=f[m]*power(v2,n-a[m].pos)%mod;
		printf("%lld\n",f[m]);
	}
	return 0;
}
