#include <bits/stdc++.h>
using namespace std;
const int block_size = 320;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const int inf = mod;
const double PI = atan(1) * 4;
template <typename T>
inline int sign(const T &a) {
  if (a < 0) return -1;
  if (a > 0) return 1;
  return 0;
}
template <typename T>
inline void in(T &x) {
  x = 0;
  T f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
long long twop(int x) { return 1LL << x; }
template <typename A, typename B>
inline void in(A &x, B &y) {
  in(x);
  in(y);
}
template <typename A, typename B, typename C>
inline void in(A &x, B &y, C &z) {
  in(x);
  in(y);
  in(z);
}
template <typename A, typename B, typename C, typename D>
inline void in(A &x, B &y, C &z, D &xx) {
  in(x);
  in(y);
  in(z);
  in(xx);
}
template <class T>
void upd(T &a, T b) {
  a = max(a, b);
}
vector<vector<int>> adj[1010];
int getSize(int from, int to) {
  for (auto &v : adj[from]) {
    if (binary_search(v.begin(), v.end(), to)) return ((int)v.size());
  }
  assert(-1 == 0);
  return 0;
}
vector<int> e[1010];
template <int maxn>
struct dsu {
  int f[maxn];
  dsu() { init(); }
  void init() {
    for (long long i = 0; i < maxn; i++) f[i] = i;
  }
  int fa(int c) {
    if (c == f[c]) return c;
    return f[c] = fa(f[c]);
  }
  void merge(int a, int b) {
    a = fa(a);
    b = fa(b);
    if (a == b) return;
    f[fa(a)] = fa(b);
  }
  bool same(int a, int b) { return fa(a) == fa(b); }
};
void dfs(int v, int p, vector<int> &vv) {
  vv.push_back(v);
  for (auto to : e[v]) {
    if (to != p) dfs(to, v, vv);
  }
}
int n;
dsu<1010> bcj;
void check() {
  int sum = 0;
  for (long long i = 1; i < (n + 1); i++) {
    sum += ((int)e[i].size());
    for (auto j : e[i]) {
      if (j > i) {
        if (bcj.same(i, j)) {
          cout << "-1";
          exit(0);
        }
        bcj.merge(i, j);
      }
    }
  }
  if (sum / 2 != n - 1)
    cout << -1;
  else {
    for (long long i = 1; i < n + 1; i++) {
      vector<vector<int>> tmp;
      for (auto to : e[i]) {
        vector<int> v;
        dfs(to, i, v);
        sort(v.begin(), v.end());
        tmp.push_back(v);
      }
      sort(tmp.begin(), tmp.end());
      if (tmp != adj[i]) cout << -1, exit(0);
    }
    cout << n - 1 << endl;
    for (long long i = 1; i < (n + 1); i++) {
      sum += ((int)e[i].size());
      for (auto j : e[i]) {
        if (j > i) {
          cout << i << " " << j << endl;
        }
      }
    }
  }
}
bool vis[1010];
int main() {
  in(n);
  for (long long i = 1; i < n + 1; i++) {
    int r = n - 1;
    while (r) {
      int cnt;
      in(cnt);
      r -= cnt;
      vector<int> v(cnt);
      for (auto &i : v) in(i);
      sort(v.begin(), v.end());
      v.erase(unique(v.begin(), v.end()), v.end());
      if (binary_search(v.begin(), v.end(), i)) cout << -1, exit(0);
      adj[i].push_back(v);
    }
    sort(adj[i].begin(), adj[i].end());
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = i + 1; j < n + 1; j++) {
      if (getSize(i, j) + getSize(j, i) == n) {
        e[i].push_back(j);
        e[j].push_back(i);
      }
    }
  }
  check();
  return 0;
}
