#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int mat[N][N], group[N][N], g[N], vis[N];
int32_t main() {
  int n;
  scanf("%d", &n);
  int x, did = 0;
  queue<int> f;
  for (int i = 1; i <= n; ++i) {
    int ga = 1, x;
    char c;
    do {
      scanf("%d%c", &x, &c);
      if (c == ':') continue;
      mat[i][x] = ga;
      group[i][ga]++;
      if (c == '-') ga++;
    } while (c != '\n');
    g[i] = ga;
    if (ga == 1) {
      did = i;
    }
  }
  if (!did) {
    cout << "-1\n";
    return 0;
  }
  vis[did] = 1;
  f.push(did);
  vector<pair<int, int>> edge;
  while (!f.empty()) {
    int at = f.front();
    f.pop();
    for (int i = 1; i <= n; ++i) {
      if (i == at) continue;
      if (mat[at][i] == -1) continue;
      group[i][mat[i][at]]--;
      group[at][mat[at][i]]--;
    }
    int mark = 0;
    for (int i = 1; i <= n; ++i) {
      if (i == at) continue;
      if (mat[at][i] == -1) continue;
      if (!group[i][mat[i][at]] && !group[at][mat[at][i]]) {
        if (mark) {
          mark = 0;
          break;
        }
        mark = 1;
        edge.push_back({i, at});
        g[i]--;
      }
      mat[i][at] = mat[at][i] = -1;
      if (g[i] == 1 && !vis[i]) {
        vis[i] = 1;
        f.push(i);
      }
    }
    if (!mark && !f.empty()) {
      cout << "-1\n";
      return 0;
    }
  }
  if (edge.size() != (n - 1)) {
    cout << "-1\n";
    return 0;
  }
  cout << edge.size() << "\n";
  for (auto c : edge) {
    cout << c.first << " " << c.second << "\n";
  }
  return 0;
}
