#include<bits/stdc++.h>
#define ll long long
using namespace std;
int T;
const int Mod=1e9+7;
const int N=1e8; 
ll n,m,v,x[N];
ll ans;
ll mul(){
	ll res=1;
	for(int i=1;i<=n-1;i++){
		if(!x[i]) continue;
		for(int j=i+1;j<=n;j++){
			//x[i]==a[i]
			if(!x[j]){
				res*=v;
				res%=Mod;
			}
		}
	}
	return res;
}
ll plu(){
	ll res=1;
	for(int i=1;i<=n-1;i++){
		res*=(v%Mod)*(v-1)%Mod;
		res%=Mod;
	}
	return res;	
}
int main(){
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	freopen("assign.in","r",stdin);
	cin>>T;
//	freopen(".out","w",stdout);
	while(T--){
//		cout<<T<<"\n";
//		memset(x,0,sizeof x);
		ans=0;
		cin>>n>>m>>v;
		int a,b;
		bool flag=0;
		for(int i=1;i<=m;i++){
			cin>>a>>b;
			if(x[a]){
				cout<<0;
				flag=1;
				break;
			}
			x[a]=b;
		}
		if(flag) continue;
		ans+=mul();
		ans%=Mod;
		cout<<mul()<<" ";
		ans+=plu();
		cout<<plu()<<"\n";
		ans%=Mod;
		cout<<ans<<"\n";
	}
	return 0;
}
/*
2 1 2
1 1
ans=4
*/
