#include<bits/stdc++.h>
using namespace std;
int t,n,m,v,c[1005],d[1005],x[1005];
void ini()
{
	for (int i = 0;i <= 1000;i++)
	{
		c[i] = 0;x[i] = 0;d[i] = 0;
	}
}
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);	
	cin>>t;
	for (int i = 1;i <= t;i++)
	{
		ini();		
		cin>>n>>m>>v;
		for (int i = 1;i <= m;i++)
		{

			cin>>c[i]>>d[i];
			if (x[c[i]] != 0)
			{
				cout<<0<<endl;
				continue;
			}
			x[c[i]] = d[i];
		}
		int ans = 0;
		for (int i = 1;i <= n;i++)
		{
			if (i == 1)
			{
				if (x[i] != 0) ans = 2;
				else ans = 1;		
			}
			else
			{
				if (x[i] != 0&&x[i - 1] != 0)
				{
					ans++;
				}
				else if (x[i] != 0&&x[i - 1] == 0)
				{
					ans *= 2;
				}
			}
		}
		cout<<ans<<endl;
		ans = 0;
	}
	return 0;
}

