#include<iostream>
#include<cstdio>
#include<algorithm>
#define mod 1000000007
#define int long long
using namespace std;
int T,n,M,m,v;
int poww(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
		{
			ret=ret*a%mod;
		}
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
struct xz
{
	int w,v;
}a[200001],A[200001];
bool cmp(xz a,xz b)
{
	return a.w<b.w;
}
signed main()
{
//	freopen("D:\\noip\\down\\day0\\assign\\assign3.in","r",stdin);
//	freopen("D:\\noip\\down\\day0\\assign\\assign3.out","w",stdout);
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>M>>v;
		for(int i=1;i<=M;i++)
		{
			cin>>A[i].w>>A[i].v;
		}
		sort(A+1,A+M+1,cmp);
		bool is0=false;
		m=0;
		a[++m]=A[1];
		for(int i=2;i<=M;i++)
		{
			if(A[i].w==A[i-1].w)
			{
				if(A[i].v!=A[i-1].v)
				{
					is0=true;
				}
			}
			else
			{
				a[++m]=A[i];
			}
		}
		if(is0)
		{
			cout<<"0\n";
			continue;
		}
//		for(int i=1;i<=m;i++)
//		{
//			cout<<a[i].w<<' '<<a[i].v<<'\n';
//		}
		int ans=poww(v,2*(a[1].w-1));
		for(int i=2;i<=m;i++)
		{
			ans=ans*(poww(v,2*(a[i].w-a[i-1].w))-poww(v,a[i].w-a[i-1].w-1)*(v-1)%mod)%mod;
		}
		ans=(ans*poww(v,2*(n-a[m].w)))%mod;
		cout<<(ans+mod)%mod<<'\n';
	}
}
/*
1
2 2 2
1 1
2 2
*/
