#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;
const int N = 100005;
const ll mod = 1000000007;

ll n, m, V;
ll a[N] = {};
ll dp[N][3] = {};

ll qpow(ll x, ll k){
	ll base = x, ret = 1ll;
	while(k){
		if(k & 1ll)  ret = (base * ret) % mod;
		base = (base*base)%mod; k >>= 1ll;
	}
	return ret %mod;
}

int main(){
	freopen("assign.in", "r", stdin);
	freopen("assign.out", "w", stdout);
	
	int T;  std:: scanf("%d", &T);
	while(T --){
		//clear
		memset(a, 0, sizeof a);
		for(int i=0; i<N; ++i)  dp[i][1] = dp[i][2] = 0;
		
		bool flag = 1;
		std:: scanf("%lld%lld%lld", &n, &m, &V);
		for(int i=1; i<=m; ++i){
			int loc; ll x;  std:: scanf("%d%lld", &loc, &x);
			if((a[loc]>0&&a[loc]!=x) || x>V)  flag = 0;
			a[loc] = x;
		}
		if(!flag)  {std:: printf("0\n"); continue ;}
		if(n == m)  {std:: printf("%lld\n", qpow(((V-1ll)*V+1ll)%mod, n-1ll) %mod); continue; }
		
		dp[1][a[1]] = 1;
		for(int i=1; i<=n; ++i){
			if(a[i]){
				if(a[i] == 1){
					dp[i][1] = (dp[i][1] + dp[i-1][1]*2ll) % mod;
					dp[i][1] = (dp[i][1] + dp[i-1][2]*2ll) % mod;
				}else{
					dp[i][2] = (dp[i][2] + dp[i-1][1]*2ll) % mod;
					dp[i][2] = (dp[i][2] + dp[i-1][2]*2ll) % mod;
				}
			}else{
				dp[i][1] = (dp[i][1] + dp[i-1][1]*2ll) % mod;
				dp[i][1] = (dp[i][1] + dp[i-1][2]*2ll) % mod;
				dp[i][2] = (dp[i][2] + dp[i-1][1]*2ll) % mod;
				dp[i][2] = (dp[i][2] + dp[i-1][2]*2ll) % mod;
			}
		}
		
		std:: printf("%d\n", (dp[n][1] + dp[n][2]) % mod);
	}
	return 0;
}
