#include <bits/stdc++.h>

const int N = 1000;
int t, n, a[N][N], amt[N], other[N];
bool u[N];
std::vector<int> g[N], ans;

void rm(int v, bool next = true) 
{
	u[v] = true;
	if (next) for (int i = 0; i < 2 * n; ++i) if (!u[i]) for (int j = 0; j < n && !u[i]; ++j) if (a[i][j] == a[v][j]) rm(i, false);
}

void either(int u, int v) 
{
	g[u].push_back(v);
	g[v].push_back(u);
}

void run(int v, bool c = 0) 
{
	u[v] = true;
	if (!c) ans.push_back(v);
	for (int i = 0; i < (int)g[v].size(); ++i) if (!u[g[v][i]]) run(g[v][i], !c);
}

int main() 
{
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (int i = 0; i < 2 * n; ++i) for (int j = 0; j < n; ++j) {
			scanf("%d", a[i] + j);
			--a[i][j];
		}
		int remove;
		do {
			remove = -1;
			for (int i = 0; i < n && remove == -1; ++i) {
				memset(amt, 0, n << 2);
				for (int j = 0; j < 2 * n; ++j) if (!u[j]) ++amt[a[j][i]];
				for (int j = 0; j < 2 * n && remove == -1; ++j) if (!u[j] && amt[a[j][i]] == 1) remove = j;
			}
			if (remove != -1) {
				ans.push_back(remove);
				rm(remove);
			}
		} while (remove != -1);
		for (int i = 0; i < n; ++i) {
			memset(other, -1, n << 2);
			for (int j = 0; j < 2 * n; ++j) if (!u[j]) {
				if (other[a[j][i]] != -1) either(other[a[j][i]], j);
				else other[a[j][i]] = j;
			}
		}
		int r = 1;
		for (int i = 0; i < 2 * n; ++i) if (!u[i]) {
			run(i);
			r += r;
			if (r >= 998244353) r -= 998244353;
		}
		printf("%d\n", r);
		for (int i = 0; i < n; ++i) printf("%d ", ans[i] + 1);
		printf("\n");
		ans.clear();
		for (int i = 0; i < 2 * n; ++i) {
			g[i].clear();
			u[i] = 0;
		}
	}
	return 0;
}
