#include <bits/stdc++.h>
using namespace std;
int n, ja[3030], grau[3030];
vector<set<int> > ramos[3030];
set<set<int> > ori[3030];
vector<pair<int, int> > ans;
vector<int> adj[3030];
void dfs(int v, int p, set<int>& pr) {
  pr.insert(v);
  for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)
    if (p != adj[v][i]) dfs(adj[v][i], v, pr);
}
int main() {
  scanf("%d", &n);
  char c;
  scanf("%c", &c);
  int cnt = 0;
  for (int(i) = (0); (i) < (n); (i)++) {
    cnt = 0;
    do {
      int k = 0;
      while (scanf("%c", &c) && '0' <= c && c <= '9') k = 10 * k + c - '0';
      set<int> lista;
      for (int(j) = (0); (j) < (k); (j)++) {
        int v = 0;
        while (scanf("%c", &c) && '0' <= c && c <= '9') v = 10 * v + c - '0';
        v--;
        lista.insert(v);
        cnt++;
      }
      ramos[i].push_back(lista);
      ori[i].insert(lista);
    } while (cnt < n - 1);
    grau[i] = ((int)(ramos[i]).size());
  }
  cnt = 0;
  queue<int> q;
  for (int(i) = (0); (i) < (n); (i)++)
    if (grau[i] == 1) q.push(i);
  while (!q.empty()) {
    cnt++;
    int v = q.front();
    q.pop();
    ja[v] = 1;
    for (int(i) = (0); (i) < (n); (i)++)
      if (!ja[i])
        for (int(j) = (0); (j) < (((int)(ramos[i]).size())); (j)++)
          if (ramos[i][j].count(v)) {
            ramos[i][j].erase(v);
            if (!((int)(ramos[i][j]).size())) {
              grau[i]--;
              ans.push_back(make_pair(i + 1, v + 1));
              adj[i].push_back(v);
              adj[v].push_back(i);
              if (grau[i] == 1) q.push(i);
            }
          }
  }
  if (cnt < n || ((int)(ans).size()) != n - 1) {
    puts("-1");
    return 0;
  }
  for (int(i) = (0); (i) < (n); (i)++) {
    set<set<int> > cur;
    for (int(j) = (0); (j) < (((int)(adj[i]).size())); (j)++) {
      set<int> prox;
      dfs(adj[i][j], i, prox);
      cur.insert(prox);
    }
    if (cur != ori[i]) {
      puts("-1");
      return 0;
    }
  }
  printf("%d\n", ((int)(ans).size()));
  for (int(i) = (0); (i) < (((int)(ans).size())); (i)++)
    printf("%d %d\n", ans[i].first, ans[i].second);
}
