#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
#define int long long
const int mod=1e9+7;
struct wt
{
	int x,y;
}w[100005];
bool cmp(wt a,wt b)
{
	if(a.x!=b.x)
	{
		return a.x<b.x;
	}
	return a.y<b.y;
}
int ksm(int x,int y)
{
	y%=mod;
	int ans=1;
	while(y!=0)
	{
		if(y%2==1)
		{
			ans*=x;
			ans%=mod;
		}
		y/=2;
		x*=x;
		x%=mod;
	}
	ans%=mod;
	return ans;
}
signed main()
{
	ios::sync_with_stdio(false);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	cin>>T;
	for(int i=1;i<=T;i++)
	{
		int n,m,v;
		cin>>n>>m>>v;
		//int v2=v*(v-1)+1;
		int con=ksm(v+1,1e9+5);
		for(int i=1;i<=m;i++)
		{
			cin>>w[i].x>>w[i].y;
		}
		sort(w+1,w+m+1,cmp);
		long long ans=1;
		if(w[m].x!=n)
		{
			w[m+1].x=n;
			w[m+1].y=0;
			m++;
		}
		for(int i=1;i<=m;i++)
		{
			if(w[i].x==w[i-1].x&&w[i].y!=w[i-1].y)
			{
				cout<<0<<endl;
				break;
			}
			if(w[i].x!=w[i-1].x)
			{
				if(i==1)
				{
					int c=w[i].x-1;
					ans=ans*ksm(v,c*2);
					ans%=mod;
					continue;
				}
				if(w[i].x==n&&w[i].y==0)
				{
					int c=w[i].x-w[i-1].x;
					ans=ans*ksm(v,c*2);
					ans%=mod;
					cout<<ans<<endl;
					continue;
				}
				int c=w[i].x-w[i-1].x;
				ans=(ans*(((ksm(v,c*2+1)+1)*con)%mod))%mod;
			}
			if(i==m)
			{
				cout<<ans<<endl;
			}
		}
	}
	return 0;
}
