#include<bits/stdc++.h>
using namespace std;
namespace MAOJUN{

typedef long long ll;
const int N=1e5+5,MOD=1e9+7;
int n,m,v;
typedef pair<int,int> pi;
#define fi first
#define se second
pi a[N];
inline ll ksm(ll x,int y){ll r=1;for(y%=MOD-1;y;y>>=1,x=x*x%MOD)if(y&1)r=r*x%MOD;return r;}

inline void slv(){
	scanf("%d%d%d",&n,&m,&v);
	for(int i=1;i<=m;i++)scanf("%d%d",&a[i].fi,&a[i].se);
	sort(a+1,a+m+1);m=unique(a+1,a+m+1)-a-1;
	for(int i=1;i<=m;i++)if(a[i].fi==a[i-1].fi){puts("0");return;}
	ll rs=1;
	for(int i=2;i<=m;i++)
		rs=(ksm(v,2*(a[i].fi-a[i-1].fi))-ksm(v,a[i].fi-a[i-1].fi-1)*(v-1))%MOD*rs%MOD;
	printf("%lld\n",(rs+MOD)*ksm(v,2*(a[1].fi-1+n-a[m].fi))%MOD);
}
inline void main(){int T;scanf("%d",&T);while(T--)slv();}

}int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	MAOJUN::main();
	return 0;
}