#include <iostream>
#include <vector>

using namespace std;

const int mod = 998244353;

void solve() {
    int n; cin >> n;
    vector<vector<int>> perms = vector<vector<int>>(2*n, vector<int>(n));
    for (auto & a : perms) {
        for (auto & b : a) {
            cin >> b;
            b--;
        }
    }
    
    int count = 1;
    vector<bool> included = vector<bool>(2*n,0); //rows chosen in final
    vector<bool> eliminated = vector<bool>(2*n,0); //eliminated rows from consideration. superset of included

    //nums[i][j] is the number of js remaining in in the ith column
    vector<vector<int>> nums = vector<vector<int>>(n, vector<int>(n,0)); 

    // indices[i][j] is a list of all indices k which has a j in the ith column
    vector<vector<vector<int>>> indices = vector<vector<vector<int>>>(n,vector<vector<int>>(n,vector<int>()));

    //xorIndices[i][j] is the xor of all indices k with a j in the ith column
    vector<vector<int>> xorIndices = vector<vector<int>>(n,vector<int>(n,0));

    //twoCount[i] is the number of j such that nums[i][j]>=2
    vector<int> twoCount = vector<int>(n,0);


    for (int i=0; i<n; i++) {
        for (int k=0; k<2*n; k++) {
            nums[i][perms[k][i]]++;
            xorIndices[i][perms[k][i]]^=k;
            indices[i][perms[k][i]].push_back(k);
            if (nums[i][perms[k][i]]==2)
                twoCount[i]++;
        }
    }

    for (int k=0; k<n; k++) {
        bool paired = 1;
        int index = -1;
        for (int i=0; i<n; i++) {
            if (twoCount[i]<n-k) {
                paired=0;
                int j = -1;
                while (nums[i][++j]!=1) {}
                index = xorIndices[i][j];
                break;
            }
        }
        if (paired) {
            count = (2*count)%mod;
            while (eliminated[++index]) {}
        }
        included[index] = 1;
        for (int i=0;i<n; i++) {
            for (auto & ell : indices[i][perms[index][i]]) {
                if (eliminated[ell])
                    continue;
                for (int j=0; j<n; j++) {
                    nums[j][perms[ell][j]]--;
                    xorIndices[j][perms[ell][j]]^=ell;
                    if (nums[j][perms[ell][j]]==1)
                        twoCount[j]--;
                    eliminated[ell] = 1;
                }
            }
        }

    }
    cout << count << '\n';
    for (int i=0; i<2*n; i++) {
        if (included[i])
            cout << i+1 << ' ';
    }
    cout << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin >> t;
    for (int i=0; i<t; i++) {
        solve();
    }
}
