#include <bits/stdc++.h>
using namespace std;
vector<string> splitstr(string s, char delim) {
  int i;
  vector<string> vec;
  string sofar = "";
  for (i = 0; i < s.length(); i++) {
    if (s[i] == delim) {
      vec.push_back(sofar);
      sofar = "";
    } else {
      sofar += s[i];
    }
  }
  vec.push_back(sofar);
  return vec;
}
int WA() {
  cout << -1 << endl;
  exit(0);
}
vector<vector<int> > adj(12345);
int compid[1234][1234];
int dfs(int cur, int par, int gao) {
  int i;
  for (i = 0; i < adj[cur].size(); i++) {
    if (adj[cur][i] == par) continue;
    if (compid[gao][cur] != compid[gao][adj[cur][i]]) WA();
    dfs(adj[cur][i], cur, gao);
  }
  return 0;
}
int visit[1234];
int dfsgen(int cur) {
  visit[cur] = 1;
  int i;
  for (i = 0; i < adj[cur].size(); i++) {
    if (visit[adj[cur][i]] == 0) dfsgen(adj[cur][i]);
  }
  return 0;
}
int confirmtree(int n) {
  dfsgen(0);
  int i;
  for (i = 0; i < n; i++) {
    if (visit[i] == 0) WA();
  }
  return 1;
}
int siz[1234][1234];
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int i, j, k;
  string s;
  for (i = 0; i < n; i++) {
    cin >> s;
    vector<string> gg = splitstr(s, '-');
    for (j = 0; j < gg.size(); j++) {
      vector<string> gao = splitstr(gg[j], ':');
      assert(gao.size() == 2);
      int sizf = stoi(gao[0]);
      vector<string> foo = splitstr(gao[1], ',');
      for (k = 0; k < foo.size(); k++) {
        int lol = stoi(foo[k]);
        siz[i][lol - 1] = sizf;
        compid[i][lol - 1] = j;
      }
    }
  }
  vector<pair<int, int> > ansvec;
  int edge = 0;
  for (i = 0; i < n; i++) {
    for (j = i + 1; j < n; j++) {
      if (siz[i][j] + siz[j][i] == n) {
        adj[i].push_back(j);
        adj[j].push_back(i);
        edge++;
        ansvec.push_back(make_pair(i, j));
      }
    }
  }
  if (edge != n - 1) {
    cout << -1 << endl;
    return 0;
  }
  if (confirmtree(n) == 0) {
    cout << -1 << endl;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < adj[i].size(); j++) {
      dfs(adj[i][j], i, i);
    }
  }
  cout << n - 1 << endl;
  for (i = 0; i < ansvec.size(); i++) {
    cout << ansvec[i].first + 1 << " " << ansvec[i].second + 1 << endl;
  }
}
