#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll T,n,m,v;
struct Num
{
	ll c,d;
	bool operator<(const Num& b)
	{
		return c<=b.c;
	}
}x[100005];
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while (T--)
	{
		ll ans=1;
		bool flag=true;
		cin>>n>>m>>v;
		for (int i=1;i<=m;i++)
			cin>>x[i].c>>x[i].d;
		sort(x+1,x+m+1);
		int p=1;
		for (int i=1;i<n;i++)
		{
			if (i==x[p].c&&p<=m)
			{
				if (x[p].c==x[p+1].c&&x[p].d!=x[p+1].d&&p<m)
				{
				 	cout<<0<<endl;
				 	flag=false;
				 	break;
			 	}
				else if (x[p].c+1==x[p+1].c&&p<m)
				{
				 	ans=(ans*(v-1)%MOD*v%MOD+ans)%MOD;
				}
				else
				{
				 	ans=ans*v%MOD*v%MOD;
				}
				while (x[p].c==x[p+1].c&&p<=m) p++;
				p++;
			}
			else
			{
				ans=ans*v%MOD*v%MOD;
			}
		}
		if (flag) cout<<ans<<endl;
	}
	return 0;
}
