#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000010
#define mod 1000000007
int t,n,m,V,d[MAXN],c,ans[MAXN][2];
int cal(int k,bool cer){
	if(k==n)return 1;
	if(ans[k][cer]!=-1)return ans[k][cer];
	if(d[k]!=0)cer=1;
	if(cer){
		ans[k][cer]=(ans[k][cer]+(d[k+1]==0?V:1)*cal(k+1,1)%mod)%mod;
		ans[k][cer]=(ans[k][cer]+(V-1)*(d[k+1]==0?V:1)*cal(k+1,0)%mod)%mod;
	}else{
		ans[k][cer]=(ans[k][cer]+V*(V-1)*(d[k+1]==0?V:1)*cal(k+1,0)%mod)%mod;
		ans[k][cer]=(ans[k][cer]+V*(d[k+1]==0?V:1)*cal(k+1,1)%mod)%mod;
	}
	return ans[k][cer];
}
void work(){
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	scanf("%d%d%d",&n,&m,&V);
	for(int i=0;i<m;++i){
		scanf("%d",&c);
		scanf("%d",d+c);
	}
	printf("%d\n",cal(0,d[0]));
}
int main(){
	scanf("%d",&t);
	while(t--){
		work();
		memset(ans,0,sizeof(ans));
		memset(d,0,sizeof(d));
	}
} 
