#include <bits/stdc++.h>
using ld = long double;
using ll = long long;
using namespace std;

int MOD = 998244353;

void solve() {
	int n; cin >> n;
	vector<vector<int>> p(n + n, vector<int>(n));
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> p[i][j]; p[i][j]--;
		}
	}
	vector<int> cnt(n);
	bool good = 1;
	vector<int> result;
	vector<int> del(n + n);
	vector<int> cros(n + n);

	int cringe = 0;

	auto accept = [&](int k) {
		del[k] = 1;
		for (int i = 0; i < n + n; i++) {
			if (del[i]) continue;
			for (int j = 0; j < n; j++) {
				if (p[i][j] == p[k][j]) {
					del[i] = 1;
					cringe = 1;
					break;
				}
			}
		}
		cros[k] = 1;
		result.push_back(k);
	};
	while (good) {
		good = 0;
		for (int i = 0; i < n; i++) {
			fill(cnt.begin(), cnt.end(), 0);
			for (int j = 0; j < n + n; j++) if (!del[j]) cnt[p[j][i]]++;
			for (int j = 0; j < n; j++) {
				if (cnt[j] == 1) {
					good = 1;
					for (int k = 0; k < n + n; k++) {
						if (!del[k] && p[k][i] == j) {
							accept(k);
							break;
						}
					}
					break;
				}
			}
			if (good) break;
		}
	}
	vector<vector<int>> g(n + n);
	for (int i = 0; i < n + n; i++) {
		for (int j = 0; j < n + n; j++) {
			for (int k = 0; k < n; k++) {
				if (del[i] && !cros[i]) continue;
				if (del[j] && !cros[j]) continue;
				if (p[i][k] == p[j][k]) g[i].push_back(j);
			}
		}
	}
	vector<int> col(n + n, -1);
	int rs = 1;

	function<void(int, int)> dfs = [&](int v, int c=0) {
		if (col[v] != -1) return;
		col[v] = c;
		for (auto u : g[v]) dfs(u, 1-c);
	};
	
	for (int i = 0; i < n + n; i++) {
		if (cros[i]) {
			if (col[i] == -1) dfs(i, 1);
		}
	}
	
	for (int i = 0; i < n + n; i++) {
		if (!del[i])
		if (col[i] == -1) rs = rs * 2 % MOD, dfs(i, 1);
	}
	cout << rs << '\n';
	for (int i = 0; i < n + n; i++) {
		if (col[i] == 1) cout << i + 1 << ' ';
	}
		cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(0);	
	cin.tie(0);
	cout.precision(30);
	int t; cin >> t;
	while (t--)
		solve();
	return 0;
}