#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1010][510], cnt[510][510], check[1010], op[1010][510];
const int mod = 998244353;
int main(){
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false); cin.tie(0);
    int T; cin>>T;
    while(T--){
        int i, j, k, N; cin>>N;
        vector <int> V;
        for(i=1; i<=2*N; i++) {
            for(j=1; j<=N; j++) cin>>a[i][j];
            V.push_back(i);
        }
        vector <int> ret2;
        while(1) {
            int flag = 0;
            for(i=0; i<V.size(); i++) for(j=1; j<=N; j++) cnt[j][a[V[i]][j]] = 0;
            for(i=0; i<V.size(); i++) {
                for(j=1; j<=N; j++) {
                    cnt[j][a[V[i]][j]]++;
                }
            }
            int ans = -1;
            vector <int> V1;
            for(i=0; i<V.size(); i++) {
                for(j=1; j<=N; j++) {
                    if(cnt[j][a[V[i]][j]] == 1) { ans = V[i]; break; }
                }
            }
            if(ans == -1) break;
            ret2.push_back(ans);
            for(i=0; i<V.size(); i++) {
                int chk = 0;
                for(j=1; j<=N; j++) {
                    if(a[V[i]][j] == a[ans][j]) chk = 1;
                }
                if(!chk) V1.push_back(V[i]);
            }

            V.clear(); V = V1;
//
//            cout<<V.size()<<"\n";
//            for(i=0; i<V.size(); i++) cout<<V[i]<<" ";
//            cout<<"\n";
        }

        if(V.size() % 2 != 0) exit(1);

        for(i=0; i<V.size(); i++) {
            int cnt = 0;
            for(j=0; j<V.size(); j++) {
                if(i == j) continue;
                for(k=1; k<=N; k++) {
                    if(a[V[i]][k] == a[V[j]][k]) {
                        op[V[i]][k] = V[j]; op[V[j]][k] = V[i];
                        cnt++;
                    }
                }
            }
        }
        int ret1 = 1; queue <int> Q;
        for(i=0; i<V.size(); i++) {
            if(!check[V[i]]) {
                ret1 *= 2; ret1 %= mod;
                Q.push(V[i]);
                check[V[i]] = 1; check[op[V[i]][1]] = 1;
                while(!Q.empty()) {
                    int X = Q.front(); Q.pop();
                    ret2.push_back(X);
                    if(X == 0) exit(1);
                    for(j=1; j<=N; j++) {
                        if(!check[ op[X][j] ] && op[X][j] != 0) {
                            check[ op[X][j] ] = 1;
                            check[ op[ op[X][j] ][1] ] = 1;
                            if(op[ op[X][j] ][1] == 0) exit(1);
                            Q.push( op[ op[X][j] ][1] );
                        }
                    }
                }
            }
        }

        for(i=1; i<=2*N; i++) for(j=1; j<=N; j++) op[i][j] = 0;
        for(i=1; i<=2*N; i++) check[i] = 0;
        cout<<ret1<<"\n";
        sort(ret2.begin(), ret2.end());
        for(i=0; i<ret2.size(); i++) cout<<ret2[i]<<" ";
        cout<<"\n";
    }
}
