#include <bits/stdc++.h>
const int Inf = 1e9;
long long LINF = (long long)1e18 + 1e17;
const long long mod = 1e9 + 7;
using namespace std;
int n;
vector<vector<int>> a[1010];
int del[1010], used[1010];
vector<vector<int>> gr;
set<set<int>> pizdec[1010];
void dfs(int v) {
  used[v] = 1;
  for (int(i) = 0; (i) < gr[v].size(); (i)++) {
    if (!used[gr[v][i]]) {
      dfs(gr[v][i]);
    }
  }
}
void dfs2(int v, set<int> &x) {
  used[v] = 1;
  x.insert(v);
  for (int(i) = 0; (i) < gr[v].size(); (i)++) {
    if (!used[gr[v][i]]) dfs2(gr[v][i], x);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  gr.resize(n);
  for (int(p) = 0; (p) < n; (p)++) {
    string s;
    cin >> s;
    vector<vector<int>> tmp;
    vector<int> t;
    set<int> lol;
    set<set<int>> kek;
    string q = "";
    int v;
    for (int(i) = 0; (i) < s.length(); (i)++) {
      if (s[i] == ',') {
        v = stoi(q) - 1;
        t.push_back(v);
        lol.insert(v);
        q = "";
      } else if (s[i] == ':') {
        q = "";
      } else if (s[i] == '-') {
        v = stoi(q) - 1;
        t.push_back(v);
        lol.insert(v);
        tmp.push_back(t);
        kek.insert(lol);
        q = "";
        t.clear();
        lol.clear();
      } else {
        q.push_back(s[i]);
      }
    }
    v = stoi(q) - 1;
    lol.insert(v);
    t.push_back(v);
    tmp.push_back(t);
    kek.insert(lol);
    a[p] = tmp;
    pizdec[p] = kek;
  }
  memset(del, 0, sizeof(del));
  for (int(q) = 0; (q) < n - 1; (q)++) {
    for (int(i) = 0; (i) < n; (i)++) {
      if (!del[i]) {
        for (int(j) = 0; (j) < a[i].size(); (j)++) {
          int can = -1, cou = 0;
          for (int(k) = 0; (k) < a[i][j].size(); (k)++) {
            if (!del[a[i][j][k]]) {
              can = a[i][j][k];
              cou++;
            }
          }
          if (can != -1 && cou == 1) {
            gr[i].push_back(can);
            gr[can].push_back(i);
            del[can] = 1;
          }
        }
      }
    }
  }
  memset(used, 0, sizeof(used));
  dfs(0);
  for (int(i) = 0; (i) < n; (i)++) {
    if (!used[i]) {
      cout << -1;
      return 0;
    }
  }
  for (int(i) = 0; (i) < n; (i)++) {
    memset(used, 0, sizeof(used));
    used[i] = 1;
    set<set<int>> kek;
    for (int(j) = 0; (j) < gr[i].size(); (j)++) {
      set<int> lol;
      dfs2(gr[i][j], lol);
      kek.insert(lol);
    }
    if (pizdec[i] != kek) {
      cout << -1;
      return 0;
    }
  }
  set<pair<int, int>> ans;
  for (int(i) = 0; (i) < n; (i)++) {
    for (int(j) = 0; (j) < gr[i].size(); (j)++) {
      pair<int, int> p = make_pair(min(i, gr[i][j]), max(i, gr[i][j]));
      ans.insert(p);
    }
  }
  cout << ans.size() << endl;
  for (auto t : ans) {
    cout << t.first + 1 << " " << t.second + 1 << endl;
  }
  return 0;
}
