#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
using LL=long long;
constexpr int N=1e5+10;
constexpr LL P=1e9+7;
int m;
LL n,v;
struct query
{
	int c,d;
	inline bool operator <(const query&_)
	{
		return c<_.c;
	}
}
q[N];
LL qpow(LL a,LL b)
{
	LL ans=1;a%=P;
	for(;b;b>>=1,a=a*a%P)
		if(b&1)
			ans=ans*a%P;
	return ans;
}
LL f[N];
void solve()
{
	scanf("%lld%d%lld",&n,&m,&v);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&q[i].c,&q[i].d);
	std::sort(q+1,q+m+1);
	int cnt=0;
	for(int i=1;i<=m;i++)
	{
		if(q[i].c==q[cnt].c&&q[i].d==q[cnt].d)
			continue;
		q[++cnt]=q[i];
	}
	LL ans=qpow(v*v,q[1].c-1);
	for(int i=2;i<=cnt;i++)
	{
		if(q[i].c==q[i-1].c)
		{
			ans=0;
			break;
		}
		ans=(qpow(v*v,q[i].c-q[i-1].c)-qpow(v,q[i].c-q[i-1].c-1)*(v-1)%P+P)%P*ans%P;
	}
	if(q[cnt].c!=n)
		ans=qpow(v*v,n-q[cnt].c)*ans%P;
	printf("%lld\n",ans);
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T=1;
	scanf("%d",&T);
	while(T--)
		solve();
	return 0;
}
/*
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
*/
//1h+
