#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const int MAXN = 1001;
vector<pair<int, vector<int> > > edges;
vector<pair<int, int> > res;
vector<vector<vector<int> > > v;
int used2[2 * MAXN];
int main() {
  string s;
  int n;
  scanf("%d", &n);
  v.resize(n);
  getline(cin, s);
  vector<int> outer;
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    for (int i = 0; i < (int)s.size(); i++)
      if (s[i] == ':' || s[i] == '-' || s[i] == ',') s[i] = ' ';
    istringstream in(s);
    int k;
    while (in >> k) {
      outer.clear();
      outer.resize(k);
      for (int j = 0; j < k; j++) {
        in >> outer[j];
        outer[j]--;
      }
      sort(outer.begin(), outer.end());
      edges.push_back(make_pair(i, outer));
      v[i].push_back(outer);
    }
  }
  queue<int> q;
  for (int i = 0; i < edges.size(); i++) {
    if (edges[i].second.size() == 1) {
      used2[i] = true;
      q.push(i);
    }
  }
  vector<int> oth(n);
  for (int i = 0; i < n; i++) oth[i] = i;
  bool ok = true;
  if (edges.size() != 2 * (n - 1)) ok = false;
  while (!q.empty() && ok) {
    int cur = q.front();
    q.pop();
    if (edges[cur].second.empty()) continue;
    int from = edges[cur].first;
    int to = edges[cur].second[0];
    oth.erase(find(oth.begin(), oth.end(), to));
    pair<int, vector<int> > destroy = make_pair(to, oth);
    bool complement_found = false;
    for (int i = 0; i < edges.size(); i++) {
      if (edges[i] == destroy) {
        complement_found = true;
        edges[i].second.clear();
        continue;
      }
      vector<int>::iterator it =
          find(edges[i].second.begin(), edges[i].second.end(), to);
      if (it != edges[i].second.end()) edges[i].second.erase(it);
    }
    if (!complement_found) {
      ok = false;
      break;
    }
    res.push_back(make_pair(from, to));
    for (int i = 0; i < edges.size(); i++) {
      if (edges[i].second.size() == 1 && !used2[i]) {
        used2[i] = true;
        q.push(i);
      }
    }
  }
  for (int i = 0; i < edges.size() && ok; i++)
    if (!edges[i].second.empty()) ok = false;
  ok &= res.size() == n - 1;
  if (!ok)
    puts("-1");
  else {
    printf("%d\n", n - 1);
    for (int i = 0; i < res.size(); i++)
      printf("%d %d\n", res[i].first + 1, res[i].second + 1);
  }
  return 0;
}
