#include <bits/stdc++.h>
#define fo(i,l,r) for(int i = (l);i <= (r);++i)
#define fu(i,l,r) for(int i = (r);i >= (l);--i)
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define ll long long
using namespace std;
void read(ll &x)
{
	x=0;char c=getchar();int fh=1;
	while(c > '9' or c < '0')
	{
		if(c == '-') fh=-1;
		c = getchar();
	}
	while(c >= '0' and c <= '9')
	{
		x = x * 10 + c - '0';
		c = getchar();
	}
	x *= fh;
	return ;
}
const int N = 1e6+5;
const ll mod = 1e9+7;
struct node{
	ll id,val;
}a[N],b[N];
ll T,n,m,v,vc[N];
bool cmp(node x,node y)
{
	return x.id < y.id;
}
ll ksm(ll x,ll y)
{
	x %= mod;
	ll ans = 1;
	while(y)
	{
		if(y&1) ans = ans*x%mod;
		x = x*x%mod;
		y >>= 1;
	}
	return ans;
}
int main()
{
	fre(assign);
	read(T);
	while(T--)
	{
		read(n),read(m),read(v);
		fo(i,1,m) read(a[i].id),read(a[i].val);
		sort(a+1,a+1+m,cmp);
		bool fl = 0;
		int cnt = 0;
		fo(i,1,m)
		{
			if(a[i].id == a[i-1].id)
			{
				if(a[i].val != a[i-1].val)
				{
					fl = 1;
					break;
				}
			}else{
				b[++cnt] = a[i];
			}
		}
		if(fl)
		{
			printf("0\n");
			continue;
		}
		if(cnt == n)
		{
			ll ds = (v*v-v+1)%mod;
			printf("%lld\n",(long long)ksm(ds,n-1));
			continue;
		}
		ll ans2 = 1;
		fo(i,2,cnt)
		{
			ll dist = b[i].id-b[i-1].id-1,pist=b[i].id-b[i-1].id;
//			cerr << "D" << dist << " " << pist << endl;
			ans2 *= (ksm(v*v%mod,pist)-ksm(v%mod,dist)+mod)%mod;
			ans2 %= mod;
		}
		ll qm=b[1].id-1,hm=n-b[cnt].id;
		ans2 = ans2*ksm(v*v%mod,qm+hm)%mod;
		printf("%lld\n",(long long)ans2);
	}
	return 0;
}
