#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N=1e5+100,mod=1e9+7;
int l,n,v,ans;
int dp[N];
struct Node{
	int p;
	int num;
}s[N];
bool cmp(Node a,Node b)
{
	return a.p<b.p;
}
int qp(int x,int y)
{
	int ret=1;
	while(y)
	{
		if( y&1 )ret=(ret*x)%mod;
		x=(x*x)%mod;
		y/=2;
	}
	return ret;
}
signed main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	cin>>T;
	bool flag=1;
	int len;
	while(T--)
	{
		cin>>l>>n>>v;
		for( int i=1 ; i<=n ; i++ )cin>>s[i].p>>s[i].num;
		sort(s+1,s+1+n,cmp);
		flag=1;
		for( int i=1 ; i<n ; i++ )
		{
			if( s[i].p==s[i+1].p && s[i].num!=s[i+1].num )
			{
				flag=0;
				break;
			}
		}
		if( flag==0 )
		{
			cout<<0<<endl;
			continue;
		}
		ans=qp(v,s[1].p*2-2);
		for( int i=2 ; i<=n ; i++ )
		{
			len=s[i].p-s[i-1].p-1;
			if( s[i].p==s[i-1].p )continue;
			ans=ans*((qp(v,2*(len+1))+mod-qp(v,len)*(v-1)%mod)%mod)%mod;
		}
		ans=ans*qp(v,(l-s[n].p)*2)%mod;
		cout<<ans<<endl;
	}
	return 0;
}
