/*Shovkoplyas Grigory in the house*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<deque>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;

#define name "gods"

int n;
vector<vector<int> > g;
vector<int> was;
vector<int> color;
bool bad;
deque<int> up, down;
vector<int> au, ad;

void dfs(int v, int c)
{
  was[v] = 1;
  color[v] = c;
  for(int i = 0; i < (int)g[v].size(); i++)
  {
    int u = g[v][i];
    if(color[u] == c)
      bad = true;
    else if(!was[u])
      dfs(u, c ^ 1);
      
  }
}

void deal(int v, int dir, int p)
{
  if(g[v].size() == 1)
    return;
  int n = g[v].size();
  if(g[v][0] != p && g[v][n - 1] != p)
  {
    if(!color[v])
    {
      assert((int)down.size() == 1);
      down.resize(0);
      for(int i = 0; i < n; i++)
      {
        int u = g[v][i];
        if(u != p && was[u])
          bad = true;
        was[u] = 1;
        down.push_back(u);
      }
    }
    else
    {
      assert((int)up.size() == 1);
      up.resize(0);
      for(int i = 0; i < n; i++)
      {
        int u = g[v][i];
        if(u != p && was[u])
          bad = true;
        was[u] = 1;
        up.push_back(u);
      }
    }
    if(!bad)
      deal(g[v][0], -1, v), deal(g[v][n - 1], 1, v);
    return; 
  }
  if(g[v][0] != p)
    reverse(g[v].begin(), g[v].end());
  for(int i = 1; i < n; i++)
  {
    int u = g[v][i];
    if(was[u])
      bad = true;
		was[u] = 1;
    if(dir == 1)
    {
      if(color[v])
        up.push_back(u);
      else
        down.push_back(u);
    }
    else
    {
      if(color[v])
        up.push_front(u);
      else
        down.push_front(u);
    } 
  }
  if(!bad)
    deal(g[v][n - 1], dir, v);
}

void make_graph(int v)
{
  was[v] = 1;
  if((int)g[v].size() == 0)
  {
    if(!color[v])
      au.push_back(v);
    else
      ad.push_back(v);
    return;
  }
  if(!color[v])
    up.push_back(v);
  else
    down.push_back(v);
  for(int i = 0; i < (int)g[v].size(); i++)  
  {
		int u = g[v][i];
    if(was[u])
      bad = true;
    was[u] = 1;
    if(color[v])
      up.push_back(u);
    else
      down.push_back(u);
  }
  deal(g[v][0], -1, v);
  if((int)g[v].size() > 1)
    deal(g[v][g[v].size() - 1], 1, v);
  for(int i = 0; i < (int)up.size(); i++)
    au.push_back(up[i]);
  for(int i = 0; i < (int)down.size(); i++)
    ad.push_back(down[i]);
	up.resize(0);
	down.resize(0);
}

int main()
{
  freopen(name".in", "r", stdin);
  freopen(name".out", "w", stdout);
  cin >> n;
  color.assign(n, -1);
  was.assign(n, 0);
  g.resize(n);
  for(int i = 0; i < n; i++)
  {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++)
    {
      int a;
      cin >> a;
      a--;
      g[i].push_back(a);
    }
  }
  for(int i = 0; i < n; i++)
    if(!was[i])
      dfs(i, 0);
  //cerr << bad << endl;
  for(int i = 0; i < n; i++)
  {
    if(g[i].size() < 3)
      continue;
    int k = 0;
    for(int j = 0; j < (int)g[i].size(); j++)
    {
      int u = g[i][j];
      if(g[u].size() > 1)
        k++;
    }
    if(k > 2)
    {
      bad = true;
      break;
    }
  }
  if(bad)
  {
    cout << "-1";
    return 0;
  }
  for(int i = 0; i < n; i++)
  {
    bool e = false;
    if(g[i].size() < 3)
      continue;
    for(int j = 0; j < (int)g[i].size(); j++)
    {
      if(g[g[i][j]].size() > 1)
      {
        if(!e)
          swap(g[i][j], g[i][0]), e = true;
        else
          swap(g[i][j], g[i][g[i].size() - 1]);
      }
    }

  }
  was.assign(n, 0);
  for(int i = 0; i < n; i++)
    if(!was[i])
      make_graph(i);
  if(bad)
  {
    cout << "-1";
    return 0;
  }
  cout << au.size() << ' ' << ad.size() << endl;
  for(int i = 0; i < (int)au.size(); i++)
    cout << au[i] + 1 << ' ';
  cout << endl;
  for(int i = 0; i < (int)ad.size(); i++)
    cout << ad[i] + 1 << ' ';
  cout << endl;
  return 0;
}

                                    

