#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
typedef long long ll;
namespace abcdefg {
	constexpr int N=1e5+7,mod=1e9+7;
	#define isdigit(x) (x>='0'&&x<='9')
	#define gc getchar_unlocked
	template <typename T>
	void read(T &x) {
		x=0;
		char ch=gc();
		for(;!isdigit(ch);ch=gc());
		for(;isdigit(ch);ch=gc()) x=(x<<3)+(x<<1)+(ch^48);
	}
	int t,n,m,v;
	struct node {
		int x,y;
	}a[N];
	bool cmp (node a,node b) { return a.x==b.x ? a.y<b.y : a.x < b.x; }
	ll ans;
	ll add(ll a,ll b) { return a+b>=mod ? a+b-mod : a+b; }
	ll ksm(ll a,ll b) {
		ll s=1;
		while(b) {
			if(b&1) s=s*a%mod;
			a=a*a%mod;
			b>>=1;
		}
		return s;
	}
	void main() {
		read(t);
		while(t--) {
			// pf("t = %d\n",t);
			read(n),read(m),read(v);
			// pf("%d %d %d\n",n,m,v);
			ans=1;
			rep(i,1,m) read(a[i].x),read(a[i].y);
			sort(a+1,a+m+1,cmp);
			ans=ksm(v,(a[1].x-1)<<1)*ksm(v,(n-a[m].x)<<1)%mod;
			// pf("???\n");
			rep(i,1,m-1) {
				if(a[i].x==a[i+1].x) {
					if(a[i].y!=a[i+1].y) {
						ans=0;
						break;
					}
					else continue;
				}
				ans=ans*add(add(ksm(v,(a[i+1].x-a[i].x)<<1),ksm(v,a[i+1].x-a[i].x-1)),mod-ksm(v,a[i+1].x-a[i].x))%mod;
			}
			pf("%lld\n",ans);
			// pf("???\n");
		}
	}
}
int main() {
	#ifdef LOCAL
	freopen("my.out","w",stdout);
	#else 
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	#endif
	abcdefg :: main();
}