#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int x[N];
int c[N];
int a[N],b[N];
int n,m,v;
long long ans=0;
void check()
{
	for(int i=1;i<=n;i++){
		c[i]=x[i];
	}
	int tmp=1;
	for(int i=1;i<n;i++)
	{
		if(c[i]==0){
			continue;
		}
		else if(c[i]==a[i])
		{
			if(c[i+1]==0)
			{
				c[i+1]=b[i];
				continue;
			}
			else if(c[i+1]!=b[i]) {
				tmp=0;
				break;
			}
		}
		else if(c[i]!=a[i])
		{
			continue;
		}
	}
	ans+=tmp;
}
void dfs(int u)
{
	if(u==n)
	{
		check();
		return;
	}
	a[u]=1;b[u]=1;
	dfs(u+1);
	a[u]=1;b[u]=2;
	dfs(u+1);
	a[u]=2;b[u]=1;
	dfs(u+1);
	a[u]=2;b[u]=2;
	dfs(u+1);
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		ans=0;
		cin>>n>>m>>v;
		bool f=1;
		for(int i=0;i<=n+1;i++){
			x[i]=0;
		}
		for(int i=1;i<=m;i++)
		{
			int u,v;
			cin>>u>>v;
			if(x[u]==0){
				x[u]=v;
			}
			else 
			{
				if(x[u]!=v)
				{
					f=0;
					break;
				}
			}
		}
		if(f==0)
		{
			cout<<0<<endl;
			continue;
		}
		dfs(1);
		cout<<ans<<endl;
	}
	return 0;
}
/*
3
2 1 2
1 1
2 2 2
1 1
2 2
2 2 2
1 1
1 2

*/
