#include<bits/stdc++.h>
using namespace std;
int n,m,v,dp[100009][2];
const int mod = 1000000007;
int ft(int a,int b){
	int x = a,y = 1;
	while(b > 0){
		if(b & 1)
			y = 1ll * y * x % mod;
		b = b >> 1;
		x = 1ll * x * x % mod;
	}
	return y;
}
struct lim{
	int pl,val;
	bool operator<(const lim &b)const{
		return pl < b.pl;
	}
}l[100009];
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d %d",&n,&m,&v);
		for(int i = 1; i <= m; i ++){
			scanf("%d %d",&l[i].pl,&l[i].val);
		}
		sort(l + 1,l + m + 1);
		int o = 1;
		bool flg = false;
		o = 1ll * o * ft(1ll * v * v % mod,l[1].pl - 1);
		for(int i = 1; i < m; i ++){
			if(l[i].pl == l[i + 1].pl && l[i].val != l[i + 1].val){//possible invalid situation
				flg = true;
				break;
			}
			else if(l[i].pl < l[i + 1].pl){//valid affective limit
				o = 1ll * o * (mod + ft(1ll * v * v % mod,l[i + 1].pl - l[i].pl) - 1ll * (v - 1) * ft(v,l[i + 1].pl - l[i].pl - 1) % mod) % mod;
			}
		} 
		o = 1ll * o * ft(1ll * v * v % mod,n - l[m].pl) % mod;
		if(flg){
			puts("0");
		}
		else{
			printf("%d\n",o);
		}
	}
}
