#include <bits/stdc++.h>
using namespace std;
const long long K = 1000;
long long where[K][K];
vector<vector<bitset<K> > > data;
vector<vector<long long> > graf;
vector<bool> used;
bitset<K> goblin;
void dfs(long long vertex) {
  used[vertex] = true;
  for (long long i = 0; i < graf[vertex].size(); i++) {
    long long to = graf[vertex][i];
    if (used[to]) continue;
    dfs(to);
  }
}
int32_t main() {
  long long n;
  cin >> n;
  long long comp = 0;
  for (long long i = 0; i < n; i++) {
    vector<long long> hh;
    used.push_back(false);
    graf.push_back(hh);
    vector<bitset<K> > help;
    string s;
    cin >> s;
    long long u = 0;
    while (u < s.size()) {
      long long number = 0;
      while (s[u] != ':') {
        long long symb = s[u] - '0';
        number = 10 * number + symb;
        u++;
      }
      u++;
      long long counter = help.size();
      bitset<K> b;
      long long vertex = 0;
      while (u < s.size() && s[u] != '-') {
        if (s[u] == ',') {
          vertex--;
          b[vertex] = 1;
          where[i][vertex] = counter;
          vertex = 0;
        } else {
          long long symb = s[u] - '0';
          vertex = 10 * vertex + symb;
        }
        u++;
      }
      vertex--;
      b[vertex] = 1;
      where[i][vertex] = counter;
      vertex = 0;
      help.push_back(b);
      comp++;
      if (comp > 2 * n - 2) {
        cout << -1 << endl;
        return 0;
      }
      u++;
    }
    data.push_back(help);
  }
  if (comp != 2 * n - 2) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<long long, long long> > ans;
  long long rebers = 0;
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      long long ind1 = where[i][j];
      long long ind2 = where[j][i];
      goblin = data[i][ind1] & data[j][ind2];
      if (goblin.none()) {
        graf[i].push_back(j);
        graf[j].push_back(i);
        ans.push_back(make_pair(i, j));
        rebers++;
      }
    }
  }
  if (rebers != n - 1) {
    cout << -1 << endl;
    return 0;
  }
  dfs(0);
  for (long long i = 0; i < n; i++) {
    if (!used[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << n - 1 << endl;
  for (long long i = 0; i < n - 1; i++) {
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
  }
  return 0;
}
