#include<bits/stdc++.h>
//#define int long long
using namespace std;
typedef long long ll;
typedef pair <ll,ll> pll;
const ll mod=1e9+7;
const int M=1e5+10;
ll t,n,m,v,ans;
ll ksm(ll a,ll k)
{
	ll res=1;
	while(k)
	{
		if(k&1)
		{
			res=1ll*res*a%mod;
		}
		a=1ll*a*a%mod;
		k>>=1;
	}
	return res;
}
void solve(ll l,ll r)
{
	ll res=ksm(v,2ll*(r-l));
	res-=ksm(v,r-l);
	res+=ksm(v,r-l-1);
	res=(res+mod)%mod;
	ans=ans*res%mod;
}
pll a[M];
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>t;
	while(t--)
	{
		cin>>n>>m>>v;
		for(int i=1;i<=m;++i)
		{
			cin>>a[i].first>>a[i].second;
		}
		sort(a+1,a+m+1);
		m=unique(a+1,a+m+1)-a-1;
		bool flag=0;
		for(int i=1;i<m;++i)
		{
			if(a[i].first==a[i+1].first)
			{
				flag=1;
				break;
			}
		}
		if(flag)
		{
			cout<<"0\n";
			continue;
		}
		ll lst=0;
		for(int i=1;i<=m;++i)
		{
			if(i==1)
			{
				ans=ksm(v,2ll*(a[i].first-1));
				lst=a[i].first;
				continue;
			}
			solve(lst,a[i].first);
			lst=a[i].first;
		}
//		cout<<m<<"\n"<<lst<<"\n";
		ans=ans*ksm(v,2ll*(n-lst))%mod;
		cout<<ans<<"\n";
	}
}
/*

1
7 1 2
4 1

4096

*/
