#include<bits/stdc++.h>
#define ll long long
#define rep(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=y;i>=x;i--)
#define file(NAME)\
	freopen(NAME".in","r",stdin),\
	freopen(NAME".out","w",stdout)
using namespace std;
const int N=1e5+5,M=0,P=1e9+7;
int n,m,v;
pair<int,int> a[N];
ll s,z;
ll qpow(ll x,ll y)
{
	ll Ans=1;
	for(;y;y>>=1,x=x*x%P)
		if(y&1) Ans=Ans*x%P;
	return Ans;
}
int main()
{
	file("assign");
	int T;scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&n,&m,&v);
		rep(i,1,m) scanf("%d%d",&a[i].first,&a[i].second);
		sort(a+1,a+m+1),m=unique(a+1,a+m+1)-a-1;
		z=qpow(v,(a[1].first-1)*2);
		rep(i,1,m-1)
		{
			s=a[i+1].first-a[i].first-1;
			if(s==-1) z=0;
			else z=z*(qpow(v,s*2+2)-qpow(v,s)*(v-1)%P+P)%P;
		}
		z=z*qpow(v,(n-a[m].first)*2)%P;
		printf("%lld\n",z);
	}
	return 0;
}
