#include <bits/stdc++.h>
using namespace std;

#define FOR(x,n) for(int x=0;x<n;x++)
#define mp make_pair
#define PI 3.14159265358979323846264338327950288
typedef long long ll;
typedef pair<int,int> ii;

const int MX = 502;
const ll MOD = 998244353;
int cts[MX], idx[MX], inans[2*MX], disabled[2*MX], vis[2*MX];
int matrix[2*MX][MX], allowed[MX][MX];
vector<int> adj[2*MX];

void res() {
  memset(cts, 0, sizeof cts);
}

void dfs(int curr, int val) {
  vis[curr] = 1;
  if(val == 0) inans[curr] = 1;
  for(int v : adj[curr]) {
    if(!vis[v]) {
      dfs(v, val ^ 1);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  int t;
  cin >> t;
  while(t--) {
    int n;
    cin >> n;

    memset(allowed, -1, sizeof allowed);
    memset(disabled, 0, sizeof disabled);
    memset(inans, 0, sizeof inans);
    memset(vis, 0, sizeof vis);
    FOR(i,2*n) {
      FOR(j,n) {
	cin >> matrix[i][j];
      }
    }

    FOR(i,2*n) {
      adj[i].clear();
    }

    while(1) {
      int added = 0;
      FOR(j,n) {
	res();
	FOR(i,2*n) {
	  if(disabled[i]) continue;
	  cts[matrix[i][j]]++;
	  idx[matrix[i][j]] = i;
	}

	for(int i = 1; i <= n; i++) {
	  if(cts[i] == 1) {
	    inans[idx[i]] = 1;
	    added++;
	  }
	}
      }

      FOR(i,2*n) {
	if(inans[i] && !disabled[i]) {
	  disabled[i] = 1;
	  FOR(k,n) {
	    allowed[k][matrix[i][k]] = 0;
	  }
	}
      }

      FOR(i,2*n) {
	if(disabled[i]) continue;
	FOR(j,n) {
	  if(!allowed[j][matrix[i][j]]) {
	    disabled[i] = 1;
	    break;
	  }
	}
      }

      if(added == 0) break;
    }

    FOR(j,n) {
      memset(idx, -1, sizeof idx);
      FOR(i,2*n) {
	if(disabled[i]) continue;
	int v = matrix[i][j];
	if(idx[v] == -1) idx[v] = i;
	else {
	  adj[idx[v]].push_back(i);
	  adj[i].push_back(idx[v]);
	}
      }
    }

    ll ans = 1;
    FOR(i,2*n) {
      if(disabled[i] || vis[i]) continue;
      dfs(i, 0);
      ans = (ans * 2) % MOD;
    }

    cout << ans << '\n';
    FOR(i,2*n) {
      if(inans[i]) cout << i + 1 << ' ';
    }
    cout << '\n';
  }
}

// UPDATE N WHEN UR DONE AAAAAAAAAAAAAAAAAAAAAAAAAAA (if it applies lol)
