#include <bits/stdc++.h>

using namespace std;

const int mod = 998244353;

int t, n, arr[1000][500], ans;
vector<int> rows;
bool done[1000];

int main() {
    cin >> t;
    while(t--) {
        cin >> n;
        for(int i = 0; i < 2 * n; i++) {
            for(int j = 0; j < n; j++) {
                cin >> arr[i][j];
            }
        }
        ans = 1;
        for(int i = 0; i < n; i++) {
            int take = -1;
            for(int j = 0; j < n; j++) {
                vector<int> cnt(n, 0), pos(n);
                for(int k = 0; k < 2 * n; k++) {
                    if(!done[k]) {
                        ++cnt[arr[k][j] - 1];
                        pos[arr[k][j] - 1] = k;
                    }
                }
                for(int k = 0; k < n; k++) {
                    if(cnt[k] == 1) {
                        take = pos[k];
                    }
                }
                if(take != -1) {
                    break;
                }
            }
            if(take == -1) {
                take = 0, ans = (ans + ans) % mod;
                while(done[take]) {
                    ++take;
                }
            }
            for(int j = 0; j < n; j++) {
                for(int k = 0; k < 2 * n; k++) {
                    if(arr[k][j] == arr[take][j]) {
                        done[k] = true;
                    }
                }
            }
            rows.push_back(take + 1);
        }
        cout << ans << endl;
        for(int i: rows) {
            cout << i << " ";
        }
        cout << endl;
        rows.clear();
        for(int i = 0; i < 2 * n; i++) {
            done[i] = false;
        }
    }
}