#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std ;
#define ll long long
const ll N = 2000 ;
ll mod = 998244353 ;
ll a[ N ][ N ] , cnt[ N ][ N ];
ll n , ans = 1 ;
bool in[ N ] , out[ N ];

void Remove( ll row ){
    if( in[row] || out[row] ) return ;
    for( int i = 0 ; i < n ; i ++ ){
        cnt[ i ][ a[row][i] ] -- ;
    }
}

void go(){
    ll mn = 100000 ;
    ll col = -1 , value = -1 ;
    for( int i = 0 ; i < n ; i ++ ){
        for( int j = 0 ; j < n ; j ++ ){
            if( cnt[i][j] == 0  ) continue ;
            if( mn > cnt[i][j] ){
                mn = cnt[i][j];
                value = j ;
                col = i ;
            }
        }
    }
    if( mn > 1 ) ans = ( ans*2 )%mod ;
    ll row = -1 ;
    for( int i = 0 ; i < 2*n ; i ++ ){
        if( in[i] || out[ i ] )continue ;
        if( a[i][col] == value ){
            row = i ;
            break ;
        }
    }
    Remove( row );
    in[ row ] = 1 ;
    for( int i = 0 ; i < 2*n ; i ++ ){
        if( in[i] || out[i] ) continue ;
        for( int j = 0 ; j < n ; j ++ ){
            if( a[i][j] == a[row][j] ){
                Remove(i) ;
                out[ i ] = 1 ;
            }
        }
    }

}

int main(){
    ll t ;
    scanf("%lld",&t);
    while( t-- ){
        scanf("%lld",&n);
        ans = 1 ;
        memset( cnt , 0 , sizeof cnt );
        memset( in , 0 , sizeof in );
        memset( out , 0 , sizeof out );
        for( int i = 0 ; i < 2*n ; i ++ ){
                for( int j = 0 ; j < n ; j ++ ){
                    scanf("%lld",&a[i][j]);
                    a[i][j]--;
                    cnt[j][ a[i][j] ]++;
                }
        }
    for( int i = 0 ; i < n ; i ++ )go();
    printf("%lld\n",ans);
    for( int i = 0 ; i < 2*n ; i ++ ){
        if( in[i] ) printf("%d " , i+1);
    }
    printf("\n");
    }
return 0 ;
}
