#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,mod=1e9+7; 
int T,n,m,v,a[N],b[N],c[N],d[N],x[N];
void solve1()
{
	int k=n*2-2,ans=0;
	for(int i=0; i<(1<<k); i++)
	{
		for(int j=1; j<=k; j++)
		{
			if(j&1)a[j/2+1]=((i>>(j-1))&1)+1;
			else b[j/2]=((i>>(j-1))&1)+1;
		}
		bool p=1;
		for(int j=1; j<n; j++)
		{
			if(x[j]==a[j]&&(x[j+1]!=b[j]&&x[j+1]>0))
			{
				p=0;
				break;
			}
		}
		if(p)ans=(ans+1)%mod;
	}
	cout<<ans<<'\n';
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>m>>v;
		memset(x,0,sizeof x);
		bool p=1;
		for(int i=1; i<=m; i++)
		{
			cin>>c[i]>>d[i];
			if(x[c[i]]>0&&x[c[i]]!=d[i])p=0;
			x[c[i]]=d[i];
		}
		if(!p)
		{
			cout<<"0\n";
			continue;
		}
		solve1();
	}
	return 0;
}
