#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e7;
const long long MOD = 1e9 + 7;
const long long K = 337;
long long getNum(long long& i, string& s, char last) {
  string res;
  for (; i < s.size() && s[i] != last; i++) {
    res.push_back(s[i]);
  }
  long long ans = 0;
  for (long long j = res.size() - 1, now = 1; j >= 0; now *= 10, j--) {
    ans += now * (res[j] - '0');
  }
  return ans;
}
vector<vector<long long>> g;
void dfs(long long v, vector<long long>& t, long long p = -1) {
  t.push_back(v);
  for (long long u : g[v]) {
    if (u != p) {
      dfs(u, t, v);
    }
  }
}
bool cmp(vector<long long>& one, vector<long long>& two) {
  if (one.size() == two.size()) return one[0] < two[0];
  return one.size() < two.size();
}
void solve() {
  long long n;
  cin >> n;
  vector<vector<vector<long long>>> a(n);
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < s.size();) {
      if (s[j] == '-') j++;
      long long x = getNum(j, s, ':');
      j++;
      vector<long long> t(x);
      for (long long c = 0; c < x; c++) {
        if (c == x - 1)
          t[c] = getNum(j, s, '-') - 1;
        else
          t[c] = getNum(j, s, ',') - 1;
        j++;
      }
      sort(t.begin(), t.end());
      a[i].push_back(t);
    }
  }
  vector<pair<long long, long long>> q(n);
  for (long long i = 0; i < n; i++) {
    q[i] = {INF, i};
    for (auto& w : a[i]) {
      q[i].first = min(q[i].first, (long long)w.size());
    }
  }
  sort(q.begin(), q.end());
  vector<pair<long long, long long>> edges;
  vector<vector<long long>> c(n, vector<long long>(n));
  for (long long i = 0; i < n; i++) {
    for (auto& w : a[i]) {
      for (long long j : w) {
        c[i][j] = w.size();
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = i + 1; j < n; j++) {
      if (c[i][j] + c[j][i] == n) edges.push_back({i, j});
    }
  }
  if (edges.size() != n - 1) {
    cout << -1;
    return;
  }
  g.resize(n);
  for (auto& p : edges) {
    g[p.first].push_back(p.second);
    g[p.second].push_back(p.first);
  }
  vector<vector<vector<long long>>> b(n);
  for (long long i = 0; i < n; i++) {
    for (long long j : g[i]) {
      vector<long long> t;
      dfs(j, t, i);
      sort(t.begin(), t.end());
      b[i].push_back(t);
    }
  }
  for (long long i = 0; i < n; i++) {
    sort(a[i].begin(), a[i].end(), cmp);
    sort(b[i].begin(), b[i].end(), cmp);
  }
  for (long long i = 0; i < n; i++) {
    if (a[i].size() != b[i].size()) {
      cout << -1;
      return;
    }
    for (long long j = 0; j < a[i].size(); j++) {
      if (a[i][j].size() != b[i][j].size()) {
        cout << -1;
        return;
      }
      for (long long c = 0; c < a[i][j].size(); c++) {
        if (a[i][j][c] != b[i][j][c]) {
          cout << -1;
          return;
        }
      }
    }
  }
  cout << n - 1 << '\n';
  for (auto& p : edges) {
    cout << (p.first + 1) << " " << (p.second + 1) << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(12);
  solve();
}
