#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 4;
pair<int, vector<int> > p[MAXN];
bool usedp[MAXN];
bool taken[MAXN];
set<pair<int, int> > ans;
vector<string> get_patch(string s) {
  vector<string> ans;
  string cur = "";
  if (0) cout << "|" << s << endl;
  for (int i = 0; i < (int)s.length(); i++) {
    if (s[i] == '-') {
      ans.push_back(cur);
      cur = "";
    } else
      cur += s[i];
  }
  ans.push_back(cur);
  return ans;
}
vector<int> get_component(string s) {
  vector<int> ans;
  int cur = 0;
  for (int i = 0; i < (int)s.length(); i++) {
    if (s[i] >= '0' && s[i] <= '9') {
      cur *= 10;
      cur += s[i] - '0';
    } else {
      if (s[i] != ':') {
        ans.push_back(cur);
      }
      cur = 0;
    }
  }
  ans.push_back(cur);
  return ans;
}
void solve() {
  int n;
  cin >> n;
  int top = 0;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    vector<string> ptch = get_patch(s);
    for (int j = 0; j < (int)ptch.size(); j++) {
      vector<int> comp = get_component(ptch[j]);
      p[top++] = make_pair(i, comp);
    }
  }
  if (top != 2 * (n - 1)) {
    cout << -1;
    return;
  }
  while (1) {
    bool was = 0;
    for (int i = 0; i < top; i++) {
      if (usedp[i]) continue;
      int leaf_cnt = 0, leaf_id = -1;
      int v = p[i].first;
      if (taken[v]) continue;
      vector<int> gr = p[i].second;
      for (int j = 0; j < (int)gr.size(); j++) {
        int to = gr[j];
        if (taken[to]) continue;
        leaf_cnt++;
        leaf_id = to;
      }
      if (leaf_cnt != 1) continue;
      was = 1;
      usedp[i] = 1;
      taken[leaf_id] = 1;
      pair<int, int> edge =
          v < leaf_id ? make_pair(v, leaf_id) : make_pair(leaf_id, v);
      ans.insert(edge);
    }
    if (!was) break;
  }
  if ((int)ans.size() != n - 1) {
    cout << -1;
    return;
  }
  set<pair<int, int> >::iterator it = ans.begin();
  cout << n - 1 << endl;
  for (; it != ans.end(); it++) {
    printf("%d %d\n", it->first, it->second);
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
