#include<bits/stdc++.h>
#define M 100010
using namespace std;
typedef long long ll;
const ll mod=1000000007;
ll qp(ll x,ll y){ll u=1;for(;y;y>>=1,x=x*x%mod)if(y&1)u=u*x%mod;return u;}
struct qq{
ll c,d;
}a[M];
ll n,m,v,T,ans;
bool o(qq x,qq y){return x.c==y.c?x.d<y.d:x.c<y.c;}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>v;
		ans=1;
		for(int i=1;i<=m;i++)cin>>a[i].c>>a[i].d;
		sort(a+1,a+m+1,o);
		for(int i=1;i<m;i++)if(a[i].c==a[i+1].c&&a[i].d!=a[i+1].d)ans=0;
		if(ans==0){cout<<"0\n";continue;}
		ans=qp(v*v%mod,a[1].c-1);
		for(int i=1;i<m;i++)
		{
			if(a[i].c==a[i+1].c)continue;
			ans=ans*(qp(v*v%mod,a[i+1].c-a[i].c)-qp(v,a[i+1].c-a[i].c)+qp(v,a[i+1].c-a[i].c-1)+mod)%mod;
		}
		ans=ans*qp(v*v%mod,n-a[m].c)%mod;
		cout<<ans<<'\n';
	} 
}
