#include <bits/stdc++.h>
using namespace std;
const int N = 1002;
const double eps = 0.000000000000000001, INF = 1e4, eps2 = 0.0001;
string s;
vector<vector<int> > ts[N];
vector<int> g[N];
int used[N];
int p[N];
int r[N];
int parent(int u) {
  if (u == p[u]) {
    return u;
  }
  return p[u] = parent(p[u]);
}
void join(int u, int v) {
  int pu = parent(u);
  int pv = parent(v);
  if (r[pu] > r[pv]) {
    swap(pu, pv);
  }
  p[pu] = pv;
  r[pv] += r[pu];
}
int nextNum(int &pos) {
  int to = 0;
  while (pos < s.length() && isdigit(s[pos])) {
    to *= 10;
    to += s[pos] - '0';
    pos++;
  }
  pos++;
  return to;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 1;
  }
  getline(cin, s);
  for (int i = 0; i < n; i++) {
    getline(cin, s);
    int pos = 0;
    while (pos < s.length()) {
      int w = nextNum(pos);
      vector<int> l(w);
      for (int j = 0; j < w; j++) {
        l[j] = nextNum(pos) - 1;
      }
      ts[i].push_back(l);
    }
  }
  for (int i = 0; i < n; i++) {
    int w = ts[i].size();
    if (w == 1) {
      used[i] = 1;
    }
  }
  bool upd = 1;
  while (upd) {
    upd = 0;
    for (int i = 0; i < n; i++) {
      if (used[i] > 1) {
        continue;
      }
      int w = ts[i].size();
      for (int j = 0; j < w; j++) {
        int vs = ts[i][j].size();
        int cnt = 0;
        int cnt2 = 0;
        int vn = -1;
        for (int k = 0; k < vs; k++) {
          int v = ts[i][j][k];
          if (used[v] == 1) {
            cnt++;
            vn = v;
          }
          if (used[v] == 2) {
            cnt2++;
          }
        }
        if (cnt == 1 && cnt2 + cnt == vs) {
          for (int k = 0; k < vs; k++) {
            int v = ts[i][j][k];
            if (parent(v) != parent(vn)) {
              cout << -1;
              return 0;
            }
          }
          g[i].push_back(vn);
          g[vn].push_back(i);
          join(vn, i);
          used[vn] = 2;
          used[i] = 1;
          upd = 1;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[i].size() != ts[i].size()) {
      cout << -1;
      return 0;
    }
  }
  cout << n - 1 << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < g[i].size(); j++) {
      if (g[i][j] > i) {
        cout << i + 1 << " " << g[i][j] + 1 << endl;
      }
    }
  }
}
