#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10,MOD=1e9+7;
inline int read(){
	int res=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch))
		flag=(ch=='-')?-1:1,
		ch=getchar();
	while(isdigit(ch))
		res=(res<<3)+(res<<1)+(ch^48),
		ch=getchar();
	return res*flag;
}
template<typename T>
inline void write(T x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

int f[N][2][2],n,m,v,flag,ans;
int qpow(int k){
	int ret=1;
	for(;k;k--){
		ret=(ret<<1)%MOD;
	}
	return ret%MOD;
}
int mp[505];
void dfs(int k){
	if(k==n) return ++ans,void();
	if(mp[k] and mp[k+1])
		dfs(k+1),
		dfs(k+1),
		dfs(k+1);
	else
		dfs(k+1),
		dfs(k+1),
		dfs(k+1),
		dfs(k+1);	
}
signed main(){
//	write(qpow(20));
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	for(int T=read();T;T--){
		ans=0;
		memset(f,0,sizeof f);
		n=read(),m=read(),v=read(),flag=0;
		for(int i=1;i<=n;i++) mp[i]=0;
		for(int i=1,c,d;i<=m;i++){
			c=read(),d=read();
			if(mp[c]){
				flag=1;
			}
			else{
				mp[c]=d;
			}
		}
		if(flag){
			write(0),putchar('\n');
			continue;
		}
		if(m==1){
			write(qpow((n-1)*2)),putchar('\n');
		}
		else{
			dfs(1);
			write(ans),putchar('\n');
		}
	}
	return 0;
}
