#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,n,k,a[1100][600],del[1100],vis[600],cho[1100],p,fans;
int main(){
	cin >> t;
	while(t--){
		cin >> n;
		for(ll i=1;i<=2*n;i++){
			del[i]=0;
			for(ll j=1;j<=n;j++){
				scanf("%lld",&a[i][j]);
			}
		}
		fans=1;
		memset(cho,0,sizeof(cho));
		for(ll k=1;k<=n;k++){
			bool f=0;
			ll idj=0;
			for(ll j=1;j<=n;j++){
				memset(vis,0,sizeof(vis));
				//printf("vis reset,j=%lld\n",j);
				for(ll i=1;i<=2*n;i++){
					if(del[i])continue;
					vis[a[i][j]]++;
					//printf("i=%lld,vis[%lld]=%lld\n",i,a[i][j],vis[a[i][j]]);
				}
				for(ll i=1;i<=n;i++){
					if(vis[i] == 1){
						//printf("column %lld,number %lld only occurred once\n",j,i);
						f=1;
						p=i;
						idj=j;
						break;
					}
				}
				if(f==1)break;
			}
			if(f){
				for(ll i=1;i<=2*n;i++){
					if(del[i])continue;
					if(a[i][idj] == p){
						p = i;
						break;
					}
				}
				//printf("f=1,line %lld is chosen\n",p);
				del[p]=1;
				cho[p]=1;
			}
			else{
				//printf("free choice\n");
				for(ll i=1;i<=2*n;i++){
					if(del[i])continue;
					p=i;
					cho[p]=1;
					del[p]=1;
					fans = fans * 2 % 998244353;
					break;
				}
				//printf("chosen line %lld\n",p);
			}
			for(ll j=1;j<=n;j++){
				for(ll i=1;i<=2*n;i++){
					if(del[i])continue;
					if(i == p)continue;
					if(a[i][j] == a[p][j])del[i]=1;//,printf("%lld deleted from it\n",i);
				}
			}
		}
		cout << fans << endl;
		for(ll i=1;i<=2*n;i++)if(cho[i])printf("%lld ",i);
		cout << endl; 
	}
	return 0;
}
