#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int f[N][N], z[N][N], p[N], vis[N], x[N], y[N];
char s[100005];
int n = 0;
int parse(int &x) {
  int res = 0;
  while (s[x] >= '0' && s[x] <= '9') {
    res = 10 * res + s[x] - '0';
    ++x;
  }
  ++x;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    int j = 0, k = 0;
    while (k < n - 1) {
      z[i][++p[i]] = parse(j);
      k += z[i][p[i]];
      for (int l = 0; l < z[i][p[i]]; ++l) {
        f[i][parse(j)] = p[i];
      }
    }
  }
  for (int l = 1; l < n; ++l) {
    int i = 1;
    while (i <= n) {
      if (!vis[i] && p[i] == 1) {
        break;
      }
      ++i;
    }
    if (i > n) {
      printf("-1");
      return 0;
    }
    int j = 1;
    while (j <= n) {
      if (!vis[j] && z[j][f[j][i]] == 1) {
        break;
      }
      ++j;
    }
    if (j > n) {
      printf("-1");
      return 0;
    }
    for (int k = 1; k <= n; ++k) {
      if (!vis[k] && k != i && k != j) {
        if (f[k][j] != f[k][i]) {
          printf("-1");
          return 0;
        }
        --z[k][f[k][i]];
      }
    }
    x[l] = i;
    y[l] = j;
    --p[j];
    vis[i] = 1;
  }
  printf("%d\n", n - 1);
  for (int l = 1; l < n; ++l) {
    printf("%d %d\n", x[l], y[l]);
  }
  return 0;
}
