import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		int [] [] a;
		foreach (row; 0..n)
		{
			a ~= readln.splitter.map !(to !(int)).array;
		}

		auto m = n / 2;
		auto z = new int [m];
		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				int d = min (row, n - 1 - row,
				    col, n - 1 - col);
				z[d] ^= a[row][col];
			}
		}
		foreach_reverse (d; 1..m)
		{
			z[d - 1] ^= z[d];
		}
		foreach (d; 1..m)
		{
			z[d] ^= z[d - 1];
		}

		int x = 0;
		int y = 0;
		foreach (row; 0..n)
		{
			foreach (col; 0..n)
			{
				if (row % 2 == 0 && col % 2 == 0 &&
				    row + col < n)
				{
					x ^= a[row][col];
				}
				if ((n - 1 - row) % 2 == 0 && col % 2 == 0 &&
				    (n - 1 - row) + col < n)
				{
					y ^= a[row][col];
				}
			}
		}

		writeln (x ^ y ^ z.fold !(q{a ^ b}));
	}
}
