#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<ctime>
#include<cmath>
#include<set>
#include<map>
#define infile(filename) freopen(filename".in","r",stdin)
#define outfile(filename) freopen(filename".out","w",stdout)
#define usefile(filename) infile(filename),outfile(filename)
using namespace std; typedef long long ll; typedef unsigned long long ull;
char gc() { static const int BUF=1<<20; static char ch[BUF],*l=ch,*r=ch; return (l==r&&(r=(l=ch)+fread(ch,1,BUF,stdin),l==r))?EOF:*l++; }
template <typename T> void read(T &a) { static char ch,fushu; fushu=a=0; do ch=gc(); while(ch!='-'&&(ch<48||ch>57)); if(ch=='-') fushu=1,ch=gc(); do a=(a<<1)+(a<<3)+(ch^48),ch=gc(); while(ch>47&&ch<58); if(fushu) a=-a; return ; }
template <typename T,typename ...Args> void read(T &a,Args &...args) { read(a),read(args...); }
const int N=100099,moder=1000000007;
int add(int x,int y) { return x+y>=moder?x+y-moder:x+y; } int Add(int &x,int y) { return x=x+y>=moder?x+y-moder:x+y; }
int sub(int x,int y) { return x<y?x-y+moder:x-y; } int Sub(int &x,int y) { return x=x<y?x-y+moder:x-y; }
int kuai(int a,int b) { if(a<0) return 0; ll rey=1,temp=a; for(;b;b>>=1) { if(b&1) rey=rey*temp%moder; temp=temp*temp%moder; } return rey; }
int T,n,m,v; pair<int,int> a[N]={};
int main()
{
	usefile("assign");
	int i,ans;
	auto calc=[&](int cnt)->int {
		return sub(kuai(v,2*cnt),(ll)kuai(v,cnt-1)*(v-1)%moder);
	};
	read(T);
	loop : --T;
	read(n,m,v);
	for(i=1;i<=m;++i)
		read(a[i].first,a[i].second);
	sort(a+1,a+1+m);
	for(i=ans=1;i<m;++i) {
		if(a[i].first==a[i+1].first) {
			if(a[i].second!=a[i+1].second) {
				ans=0; break;
			}
		} else {
			ans=(ll)ans*calc(a[i+1].first-a[i].first)%moder;
		}
	}
	if(1<a[1].first) ans=(ll)ans*kuai(v,2*(a[1].first-1))%moder;
	if(a[m].first<n) ans=(ll)ans*kuai(v,2*(n-a[m].first))%moder;
	printf("%d\n",ans);
	if(T) goto loop;
}
