/*input
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 10;
const int mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool collide(vector<int>&a, vector<int>&b) {
	assert(sz(a) == sz(b));
	for (int i = 0; i < sz(a); i++) {
		if (a[i] == b[i]) {
			return true;
		}
	}
	return false;
}
void solve_case() {
	int n;
	cin >> n;
	vector<int>answer;
	vector<int>removed(2 * n);
	vector<vector<int> >cnt(n, vector<int>(n));
	vector<vector<int> >v;
	for (int i = 0; i < 2 * n; i++) {
		vector<int>cur(n);
		for (int j = 0; j < n; j++) {
			cin >> cur[j];
			cur[j]--;
			cnt[j][cur[j]]++;
		}
		v.pb(cur);
	}

	ll ways = 1;
	auto remove_vec = [&](int i) {
		removed[i] = 1;
		for (int j = 0; j < n; j++) {
			cnt[j][v[i][j]]--;
		}
	};
	auto add_vec = [&]() {
		int idx = -1;
		ll mul = 2;
		for (int i = 0; i < 2 * n; i++) {
			if (!removed[i]) {
				for (int j = 0; j < n; j++) {
					if (cnt[j][v[i][j]] == 1) {
						idx = i;
					}
				}
				if (idx == i) {
					mul = 1;
					break;		
				} else {
					idx = i;
				}
			}
		}
		ways = ways * mul % mod;
		
		assert(idx != -1);
		answer.pb(idx);
		remove_vec(idx);

		for (int i = 0; i < 2 * n; i++) {
			if (!removed[i] && collide(v[idx], v[i])) {
				remove_vec(i);
			}
		}
	};

	for (int i = 0; i < n; i++) {
		add_vec();
	}

	cout << ways << "\n";
	for (int i : answer) {
		cout << i + 1 << " ";
	}
	cout << "\n";
}
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	int t;
	cin >> t;
	while (t--) {
		solve_case();
	}
	return 0;
}