#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5,p=1e9+7;
int t,n,m,v;
struct query{
	int x,y;
	bool operator ==(query a){return x==a.x&&y==a.y;}
}q[N+5];
bool cmp(query x,query y){return x.x<y.x;}
int fpow(int x,int y){
	if(!y)return 1;
	int ret=fpow(x,y>>1);
	return ret*ret%p*(y&1?x:1)%p;
}
void mul(int &x,int y){x=x*y%p;}
signed main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++)cin>>q[i].x>>q[i].y;
		sort(q+1,q+m+1,cmp);
		m=unique(q+1,q+m+1)-q-1;
		int ans=fpow(v,2*(q[1].x-1));
		for(int i=1;i<m;i++){
			if(q[i].x==q[i+1].x){
				ans=0;
				break;
			}
			if(q[i].x==q[i+1].x-1)mul(ans,((v-1)*v%p+1)%p);
			else mul(ans,(fpow(v,2*(q[i+1].x-q[i].x))-fpow(v,q[i+1].x-q[i].x-1)*(v-1)%p+p)%p);
		}
		mul(ans,fpow(v,2*(n-q[m].x)));
		cout<<ans<<'\n';
	}
}
