#include <fstream>
#include <algorithm>
#define DIM 205
#define infile "xerox.in"
#define outfile "xerox.out"
using namespace std;
ifstream fin(infile);
ofstream fout(outfile);
int main() {
int querysCount;
fin >> querysCount;
for (; querysCount; --querysCount) {
int n, bullshit;
fin >> n >> bullshit >> bullshit;
int xorSum = 0;
for (int i = 1; i <= n; ++i) {
int m;
fin >> m;
xorSum ^= m;
for (int j = 1; j <= 2 * m; ++j)
fin >> bullshit;
}
fout << (xorSum ? 1 : 0) << '\n';
}
return 0;
}
//Trust me, I'm the Doctor!
//Miriam e tare!