#include <bits/stdc++.h>
using namespace std;
vector<set<int> > v[1010];
vector<int> a, b;
int c[1010][1010];
bool used[1010];
int main() {
  int n, i, j, l, t = 0;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    int p = 0, k = 0;
    while (p != n - 1) {
      int x;
      char y;
      scanf("%d %c", &x, &y);
      p += x;
      set<int> g;
      for (j = 0; j < x; j++) {
        int z;
        scanf("%d", &z);
        c[i][z] = k;
        g.insert(z);
        if (j != x - 1) scanf(" %c", &y);
      }
      if (p != n - 1) scanf(" %c", &y);
      v[i].push_back(g);
      k++;
    }
    t += k;
  }
  set<pair<int, pair<int, int> > > s;
  for (i = 1; i <= n; i++)
    for (j = 0; j < v[i].size(); j++)
      s.insert(
          pair<int, pair<int, int> >(v[i][j].size(), pair<int, int>(i, j)));
  for (i = s.size() - 1; i >= 0; i--) {
    if (s.empty()) break;
    int x = s.begin()->second.first;
    int y = s.begin()->second.second;
    int z = *v[x][y].begin();
    if (used[z]) {
      s.erase(s.begin());
      continue;
    }
    used[z] = true;
    if (v[x][y].size() != 1) {
      t = 1e9;
      break;
    }
    a.push_back(x);
    b.push_back(z);
    for (j = 1; j <= n; j++)
      if (!used[j]) {
        v[j][c[j][z]].erase(z);
        if (x != j && v[j][c[j][z]].find(x) == v[j][c[j][z]].end()) {
          t = 1e9;
          break;
        }
        s.erase(pair<int, pair<int, int> >(v[j][c[j][z]].size() + 1,
                                           pair<int, int>(j, c[j][z])));
        if (v[j][c[j][z]].size())
          s.insert(pair<int, pair<int, int> >(v[j][c[j][z]].size(),
                                              pair<int, int>(j, c[j][z])));
      }
    s.erase(pair<int, pair<int, int> >(z, pair<int, int>(x, y)));
  }
  if (a.size() != n || t != 2 * (n - 1))
    printf("-1\n");
  else {
    printf("%d\n", n - 1);
    for (i = 0; i < n - 1; i++) printf("%d %d\n", a[i], b[i]);
  }
  return 0;
}
