#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
const long long mod=998244353;
typedef pair<int,int> pii;
int n,x,y,s,t;
int a[maxn*2+5][maxn+5],b[maxn+5][maxn+5],f[maxn+5];
vector <pii> v;
vector <int> c[maxn+5][maxn+5];
int main()
{
    int T;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d",&n);
        for (int i=1;i<=n;i++)
        {
            for (int j=1;j<=n;j++)
            {
                b[i][j]=0;
                c[i][j].clear();
            }
        }
        for (int i=1;i<=n*2;i++)
        {
            f[i]=0;
            for (int j=1;j<=n;j++)
            {
                scanf("%d",&a[i][j]);
                b[j][a[i][j]]++;
                c[j][a[i][j]].push_back(i);
            }
        }
        int top=0,tail=0;
        int cnt=0,idx=1;
        long long ans=1;
        v.clear();
        for (int i=1;i<=n;i++)
        {
            for (int j=1;j<=n;j++)
            {
                if (b[i][j]==1)
                {
                    tail++;
                    v.push_back(pii(i,j));
                }
            }
        }
        while (cnt<n)
        {
            if (top<tail)
            {
                x=v[top].first;
                y=v[top].second;
                if (b[x][y]!=1)
                {
                    top++;
                    continue;
                }
                for (int i=0;i<c[x][y].size();i++)
                {
                    if (f[c[x][y][i]]==0)
                    {
                        t=c[x][y][i];
                        break;
                    }
                }
            }
            else
            {
                while (f[idx]!=0)
                {
                    idx++;
                }
                t=idx;
                ans=ans*2%mod;
            }
            f[t]=1;
            cnt++;
            for (int i=1;i<=n;i++)
            {
                b[i][a[t][i]]=0;
            }
            for (int i=1;i<=n;i++)
            {
                for (int j=0;j<c[i][a[t][i]].size();j++)
                {
                    s=c[i][a[t][i]][j];
                    if (f[s]==0)
                    {
                        f[s]=2;
                        for (int k=1;k<=n;k++)
                        {
                            b[k][a[s][k]]--;
                            if (b[k][a[s][k]]==1)
                            {
                                tail++;
                                v.push_back(pii(k,a[s][k]));
                            }
                        }
                    }
                }
            }
            top++;
        }
        s=0;
        printf("%lld\n",ans);
        for (int i=1;i<=n*2;i++)
        {
            if (f[i]==1)
            {
                s++;
                if (s<n) printf("%d ",i); else printf("%d\n",i);
            }
        }
    }
}