#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=100010,mod=1e9+7;
int T,n,m,v,f[N],P[N*20];
struct node{
	int c,d;
	bool operator<(node b)const
	{
		if(c!=b.c) return c<b.c;
		return d<b.d;
	}
	bool operator ==(node b)const
	{
		return c==b.c&&d==b.d;
	}
}a[N];
int qpow(int a,int b)
{
	int s=1;
	while(b)
	{
		if((b&1)) s=s*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return s;
}
int All(int l,int r)
{
	if(l>r) return 1;
	if((r-l+1<<1)<=2000000) return P[r-l+1<<1];
	return qpow(v,(r-l+1)<<1);
}
int Con(int l,int r)
{
	if(l>r) return 1;
	if(r-l<=2000000) return P[r-l];
	return qpow(v,r-l);
}
int Broken(int l,int r)
{
	return (All(l,r)+mod-Con(l,r)*v%mod+mod)%mod;
}
void add(int &a,int b)
{
	a+=b;
	if(a>=mod) a-=mod;
}
signed 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;
		P[0]=1;
		for(int i=1;i<=2000000;i++) P[i]=P[i-1]*v%mod;
		for(int i=1;i<=m;i++) cin>>a[i].c>>a[i].d;
		sort(a+1,a+m+1);
		bool fl=0;
		for(int i=2;i<=m;i++)
		{
			if(a[i].c==a[i-1].c&&a[i].d!=a[i-1].d)
			{
				fl=1;
				break;
			}
		}
		if(fl)
		{
			cout<<"0\n";
			continue;
		}
		m=unique(a+1,a+m+1)-a-1;
		f[m]=All(a[m].c,n-1);
		for(int i=m-1;i>=1;i--)
		{
			f[i]=0;
			int conn=1;
			for(int j=i+1;j<=m;j++)
			{
				int F=conn*f[j]%mod;
				F=F*Broken(a[j-1].c,a[j].c-1)%mod;
				add(f[i],F);
				conn=conn*Con(a[j-1].c,a[j].c-1)%mod;
			}
			add(f[i],conn*All(a[m].c,n-1)%mod);
		}
		cout<<f[1]*All(1,a[1].c-1)%mod<<"\n";
	}
	return 0;
}
/*
1
10 11 2
10 2
7 2
7 2
2 2
3 2
4 2
10 2
7 2
10 2
3 2
3 2

3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2

*/
