#include <bits/stdc++.h>
using namespace std;
struct node {
  long long siz, fa;
  bool vis;
} a[1001];
string s;
long long n, cnt[1001][1001];
vector<long long> e[1001];
vector<vector<long long> > t[1001];
vector<pair<long long, long long> > ans;
void dfs(long long x) {
  a[x].siz = a[x].vis = 1;
  for (long long v : e[x])
    if (v != a[x].fa) {
      if (a[v].vis) cout << "-1", exit(0);
      a[v].fa = x, dfs(v), a[x].siz += a[v].siz;
    }
}
vector<vector<long long> > tmp;
void check(long long u, long long fa) {
  tmp.back().push_back(u);
  for (long long v : e[u])
    if (v != fa) check(v, u);
}
inline void chec() {
  for (long long u = 1; u <= n; u++) {
    tmp.clear();
    for (long long v : e[u]) {
      tmp.push_back(vector<long long>());
      check(v, u);
      sort(tmp.back().begin(), tmp.back().end());
    }
    sort(tmp.begin(), tmp.end());
    if (t[u] != tmp) cout << "-1\n", exit(0);
  }
}
inline long long get_num() {
  char temp = s.back();
  s.pop_back();
  long long ans = 0;
  while (temp >= '0' && temp <= '9') {
    ans = ans * 10 + temp - '0';
    if (s.empty()) break;
    temp = s.back(), s.pop_back();
  }
  return ans;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> s, reverse(s.begin(), s.end());
    long long d, tot = 0;
    while (tot < n - 1) {
      t[i].push_back(vector<long long>());
      d = get_num(), tot += d;
      for (long long j = 1; j <= d; j++)
        t[i].back().push_back(get_num()), cnt[i][t[i].back().back()] = d;
      sort(t[i].back().begin(), t[i].back().end());
    }
    sort(t[i].begin(), t[i].end());
  }
  for (long long u = 1; u <= n; u++)
    for (long long v = u + 1; v <= n; v++)
      if (cnt[u][v] + cnt[v][u] == n)
        e[u].push_back(v), e[v].push_back(u), ans.push_back(make_pair(u, v));
  if ((long long)ans.size() != (n - 1)) cout << "-1", exit(0);
  dfs(1);
  if (a[1].siz != n) cout << "-1", exit(0);
  chec();
  cout << ans.size() << '\n';
  for (auto t : ans) cout << t.first << ' ' << t.second << '\n';
  return 0;
}
