#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i ++)
#define mx 505
#define LL long long
#define mod 998244353
using namespace std;

int n, cnt[mx][mx], a[mx * 2][mx], chk[mx * 2], ans[mx];
int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif

	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);

	int tc; cin >> tc;
	
	while(tc --){
		LL rlt = 1;
		cin >> n;
		memset(chk, 0, sizeof(chk));
		for (int i = 0; i < n * 2; i ++) {
			for (int j = 0; j < n ; j ++) {
				cin >> a[i][j];
				cnt[a[i][j]][j] ++;
			}
		}
		for (int ca = 0; ca < n ; ca ++){
			int se = -1;
			for (int i = 0; i < n * 2; i ++) if (!chk[i]) {
				for (int j = 0; j < n; j ++) if (cnt[a[i][j]][j] == 1) {
					se = i;
					break;
				}
				if (se > -1)break;
			}
			if (se == -1) {
				se = 0;
				rlt = (rlt * 2) % mod; 
				while (chk[se]) se ++;
			}
			for (int i = 0; i < n * 2; i ++) if (!chk[i]) {
				for (int j = 0; j < n; j ++) if (a[i][j] == a[se][j]) {
					chk[i] = 1;
					break;
				}
				if (chk[i]) {
					for (int j = 0; j < n; j ++) {
						cnt[a[i][j]][j] --;
					}
				}
			}
			ans[ca] = se;
		}
		cout << rlt << endl;
		for (int i = 0; i < n; i ++) cout << ans[i] + 1 << " ";
		cout << endl;
	}
	return 0;
}

