#include<cstdio>
using namespace std;
namespace IO
{
	const int lim=1000000;
	int curin,topin,topout;
	char in[lim+100],out[lim+100];
	char get()
	{
		if(curin==topin)
		{
			curin=0;
			topin=fread(in,1,lim,stdin);
		}
		if(topin==0)
		return 0;
		return in[curin++];
	}
	void read(long long &x,int l=100)
	{
		int len=1;
		char c=get();
		while(c<'0'||c>'9')
		c=get();
		x=c-'0';
		while(len<l)
		{
			c=get();
			if(c<'0'||c>'9')
			return;
			x=x*10+c-'0';
		}
	}
	void flush()
	{
		fwrite(out,1,topout,stdout);
		topout=0;
	}
	class _{public:~_(){flush();}}__;
	void put(char c)
	{
		if(topout==lim)
		flush();
		out[topout++]=c;
	}
	void print(long long x)
	{
		if(x<10)
		put(x+'0');
		else
		{
			print(x/10);
			put(x%10+'0');
		}
	}
}
using IO::put;
using IO::read;
using IO::print;
const long long mod=1000000007;
long long T,I,i,n,m,v,c[110000],d[110000],q1[110000],q2[110000],ans;
long long power(long long a,long long b)
{
	long long k=a,ans=1;
	while(b)
	{
		if(b&1)
		ans=ans*k%mod;
		k=k*k%mod;
		b=b>>1;
	}
	return ans;
}
void sort(long long l,long long r)
{
	long long mid=(l+r)/2,i=l,j=mid+1,k=l;
	if(l==r)
	{
		q1[l]=c[l];
		q2[l]=d[l];
		return;
	}
	sort(l,mid);
	sort(mid+1,r);
	while(i<=mid&&j<=r)
	{
		if(q1[i]<=q1[j])
		{
			c[k]=q1[i];
			d[k]=q2[i];
			i++;
		}
		else
		{
			c[k]=q1[j];
			d[k]=q2[j];
			j++;
		}
		k++;
	}
	while(i<=mid)
	{
		c[k]=q1[i];
		d[k]=q2[i];
		i++;
		k++;
	}
	while(j<=r)
	{
		c[k]=q1[j];
		d[k]=q2[j];
		j++;
		k++;
	}
	for(i=l;i<=r;i++)
	{
		q1[i]=c[i];
		q2[i]=d[i];
	}
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	read(T);
	for(I=1;I<=T;I++)
	{
		read(n);
		read(m);
		read(v);
		for(i=1;i<=m;i++)
		{
			read(c[i]);
			read(d[i]);
		}
		sort(1,m);
		for(i=1;i<m;i++)
		if(c[i]==c[i+1]&&d[i]!=d[i+1])
		break;
		if(i<m)
		{
			print(0);
			put('\n');
			continue;
		}
		ans=0;
		for(i=1;i<=m;i++)
		if(c[i]!=c[i-1])
		{
			ans++;
			c[ans]=c[i];
		}
		m=ans;
		ans=power(v,2*(c[1]-1)+2*(n-c[m]));
		for(i=1;i<m;i++)
		ans=ans*(power(v,2*(c[i+1]-c[i]))-power(v,c[i+1]-c[i]-1)*(v-1)%mod+mod)%mod;
		print(ans);
		put('\n');
	}
	return 0;
}
