#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 505, p = 998244353;
int t, n, a[maxn<<1][maxn], ans, s[maxn], tot, cnt, b[maxn][maxn];
int pre[maxn<<1], nxt[maxn<<1];
bool check(int u) {
	++cnt;
	for(int i = 1; i <= n; ++i)
		if(b[i][a[u][i]] == 1) return true;
	return false;
}
void del(int u) {
	pre[nxt[u]] = pre[u], nxt[pre[u]] = nxt[u];
	for(int i = 1; i <= n; ++i) b[i][a[u][i]]--;
}
void solve(int u) {
	cnt = 0;
	for(int i = 1; i <= n; ++i) {
		int v = nxt[u];
		while(v != u) {
			if(a[u][i] == a[v][i])  del(v);
			v = nxt[v];
		}
	}
	s[++tot] = u;
	del(u);
}
int main() {
	cin >> t;
	while(t--) {
		ans = 1, tot = cnt = 0;
		memset(b, 0, sizeof b);
		cin >> n;
		for(int i = 1; i <= n<<1; ++i) {
			for(int j = 1; j <= n; ++j)
				cin >> a[i][j], b[j][a[i][j]]++;
			pre[i] = i - 1, nxt[i] = i + 1;
		}
		pre[1] = n<<1, nxt[n<<1] = 1;
		int u = 1;
		while(tot != n) {
			if(check(u)) solve(u);
			else if(cnt+tot == n<<1) solve(u), ans = ans * 2ll % p;
			u = nxt[u];
		}
		cout << ans << endl;
		for(int i = 1; i <= tot; ++i)
			cout << s[i] << " ";
		cout << endl;
	}
}