#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll mod = 998244353;
bool adj[1005][1005];
bool del[1005], marked[1005];
ll cnt[505][505];
ll perm[1005][505];
ll n;
void del_p(ll id){
	for (ll j = 1; j <= n; j++) cnt[j][perm[id][j]]--;
}
void solve(){
	cin >> n;
	for (ll i = 1; i <= n; i++){
		for (ll j = 1; j <= n; j++) cnt[i][j] = 0;
	}
	for (ll i = 1; i <= 2 * n; i++) del[i] = marked[i] = 0;
	for (ll i = 1; i <= 2 * n; i++){
		for (ll j = 1; j <= n; j++){
			cin >> perm[i][j];
			cnt[j][perm[i][j]]++;
		}
	}
	for (ll i = 1; i <= 2 * n; i++){
		for (ll j = 1; j <= 2 * n; j++) adj[i][j] = (i == j);
	}
	for (ll i = 1; i <= 2 * n; i++){
		for (ll j = i + 1; j <= 2 * n; j++){
			for (ll k = 1; k <= n; k++){
				if (perm[i][k] == perm[j][k]) adj[i][j] = 1;
			}
			adj[j][i] = adj[i][j];
		}
	}
	ll ans = 1;
	for (ll _ = 1; _ <= n; _++){
		bool term = 0;
		for (ll i = 1; i <= 2 * n; i++){
			if (term) break;
			if (del[i]) continue;
			for (ll j = 1; j <= n; j++){
				if (cnt[j][perm[i][j]] == 1){
					marked[i] = 1;
					for (ll k = 1; k <= 2 * n; k++){
						if (del[k]) continue;
					 	if (adj[i][k]){
					 		del_p(k);
					 		del[k] = 1;
						}
					}
					term = 1;
					break;
				}
			}
		}
		if (!term){
			(ans *= 2) %= mod;
			for (ll i = 1; i <= 2 * n; i++){
				if (!del[i]){
					marked[i] = 1;
					for (ll k = 1; k <= 2 * n; k++){
						if (del[k]) continue;
						if (adj[i][k]){
							del_p(k);
							del[k] = 1;
						}
					}
					break;
				}
			}
		}
	}
	cout << ans << "\n";
	ll cnt_mark = 0;
	for (ll i = 1; i <= 2 * n; i++){
		if (marked[i]) cnt_mark++, cout << i << " ";
	}
	assert(cnt_mark == n);
	cout << "\n";
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll t; cin >> t;
	while (t--) solve();
}