#include <iostream>
#include <vector>
using namespace std;

int M, N;
vector < int > v;

void scan(){
	cin	>> M >> N;
	
	v.erase ( v.begin(), v.end() );
	
	for ( int i = 0; i < N; ++i ){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		
		v.push_back ( x2 - x1 - 1);
		v.push_back ( y2 - y1 - 1);
	}
}

void solve(){
	int xr = v[0];
	
	for ( int i = 1; i < v.size(); ++i )
		xr ^= v[i];
	
	if ( !xr ) cout << 0;
	else cout << 1;
}

int main(){
	int tests;
	
	cin >> tests;
	
	while ( tests-- ) {
		scan();
		solve();
	}
	
	cout << endl;
}
