/*
	[NWERC'10] Telephone Network Solution Checker
	by: Jan Kuipers

	Note: this checker assumes that the output is properly formatted and
	consists of numbers fitting in 32 bit integers. Use "checktestdata"
	to confirm this before this checker is used.
*/

#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int n,m;

pair<int,int> check (vector<int> a, vector<int> b) {
	
	vector<vector<int> > used(n, vector<int>(1<<n, -1));

	for (int i=0; i<m; i++) {
		for (int j=n-1; j>=0; j--) {
			
			a[i] ^= a[i] & (1<<j);
			a[i] ^= b[i] & (1<<j);

			if (used[j][a[i]] != -1)
				return make_pair(used[j][a[i]], i);

			used[j][a[i]] = i;
		}		
	}

	return make_pair(-1,-1);
}

int main (int argc, char **argv) {
	
	if ( argc<3 ) {
		cerr << "Invalid number of arguments." << endl;
		return 1;
	}
	
	ifstream testin(argv[1]);
	ifstream progout(argv[2]);

	int runs;
	testin >> runs;

	for (int run=1; run<=runs; run++) {
		testin >> n >> m;

		vector<int> a(m),b(m),c(m);
		for (int i=0; i<m; i++) {
			testin >> a[i] >> b[i];
			progout >> c[i];

			if (c[i]<0 || c[i]>=(1<<n)) {
				cout << "Testcase " << run << " incorrect: ";
				cout << "Number not between 0 and 2^n-1" << endl;
				return 0;
			}
		}

		pair<int,int> x = check(a,c);
		if (x.first != -1) {
			cout << "Testcase " << run << " incorrect: ";
			cout << "Input paths " << x.first << " and " << x.second << " are not disjoint." << endl;
			return 0;
		}

		x = check(b,c);
		if (x.first != -1) {
			cout << "Testcase " << run << " incorrect: ";
			cout << "Output paths " << x.first << " and " << x.second << " are not disjoint." << endl;
			return 0;
		}
	}

	cerr << "Correct" << endl;
	return 0;
}

	
