#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int t,n,m,v,a[100005],x,y,flag,cnt;
long long dfs(int x){
	if(x==n+1) return 1;
	long long sum = 0;
	if(!a[x]){
		sum += (v-1)*v*dfs(x+1);
		a[x] = a[x+1] = 1;
		if(!a[x+1]) dfs(x+1);
		a[x] = a[x+1] = 0;
	}
	else{
		a[x+1] = 1;
		sum += dfs(x+1);
		a[x+1] = 0;
		sum += (v-1)*dfs(x+1);
	}
	cout << x << ' ' << sum << endl;
	return sum%mod;
}
int main(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin >> t;
	while(t--){
		cin >> n >> m >> v;
		flag = 0;
		memset(a,0,sizeof(a));
		for(int i=1;i<=m;i++){
			cin >> x >> y;
			if(a[x]&&a[x]!=y){
				flag = 1;
				cout << "0\n";
				break;
			}else a[x]=y;
		}
		if(flag) continue;
		cout << dfs(1) << "\n";
	} 
	return 0;
}

