#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > e[1010];
int done[1010];
int wh[1010][1010];
int cn[1010];
int cnn[1010][1010];
vector<int> ans;
vector<int> tmp;
vector<int> g[1010];
int f;
void dfs(int v, int p) {
  done[v] = 1;
  tmp.push_back(v);
  for (int i = 0; i < g[v].size(); i++) {
    if (p != g[v][i]) {
      if (done[g[v][i]]) {
        f = 1;
      } else {
        dfs(g[v][i], v);
      }
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int cnt = n - 1, l, x, p = 0;
    while (cnt) {
      scanf("%d%*c", &l);
      vector<int> v;
      for (int j = 0; j < l; j++) {
        scanf("%d%*c", &x);
        --x;
        wh[x][i] = cn[i];
        --cnt;
        v.push_back(x);
      }
      cnn[i][cn[i]] = l;
      cn[i]++;
      sort(v.begin(), v.end());
      e[i].push_back(v);
    }
    sort(e[i].begin(), e[i].end());
  }
  while (1) {
    vector<int> l;
    for (int i = 0; i < n; i++) {
      if (done[i]) continue;
      if (cn[i] == 1) {
        l.push_back(i);
      }
    }
    if (!l.size()) break;
    for (int i = 0; i < l.size(); i++) {
      int x = l[i];
      done[x] = 1;
      for (int j = 0; j < n; j++) {
        if (done[j]) continue;
        if (!--cnn[j][wh[x][j]]) {
          ans.push_back(x);
          ans.push_back(j);
          g[x].push_back(j);
          g[j].push_back(x);
          --cn[j];
        }
      }
    }
  }
  int s = 0;
  for (int i = 0; i < n; i++) {
    s += done[i];
    if (!done[i] && cn[i]) {
      printf("-1\n");
      return 0;
    }
  }
  if (s < n - 1) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      done[j] = 0;
    }
    vector<vector<int> > r;
    for (int j = 0; j < g[i].size(); j++) {
      int to = g[i][j];
      tmp.clear();
      dfs(to, i);
      sort(tmp.begin(), tmp.end());
      r.push_back(tmp);
    }
    sort(r.begin(), r.end());
    if (f || r != e[i]) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d\n", n - 1);
  for (int i = 0; i < n - 1; i++) {
    printf("%d %d\n", ans[i * 2] + 1, ans[i * 2 + 1] + 1);
  }
  return 0;
}
