#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > a[1111];
set<pair<int, int> > se[1111];
vector<pair<int, int> > h[1111];
vector<int> g[1111];
int reb = 0;
bool was[1111];
int cmp = 0;
void dfs(int v) {
  was[v] = 1;
  cmp++;
  for (int to : g[v])
    if (!was[to]) dfs(to);
}
const int p = 31;
const int p2 = 37;
const int mod = (int)1e9 + 7;
int bp(int a, int k) {
  if (k == 1) return a;
  if (k % 2 == 0) {
    int q = bp(a, k / 2);
    return q * (long long)q % mod;
  } else {
    return bp(a, k - 1) * (long long)a % mod;
  }
}
pair<int, int> getHash(vector<int> &a) {
  int ans = 0;
  int ans2 = 0;
  for (int first : a) {
    ans += bp(p, first);
    if (ans >= mod) ans -= mod;
    ans2 += bp(p2, first);
    if (ans2 >= mod) ans2 -= mod;
  }
  return make_pair(ans, ans2);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    s += '-';
    vector<int> now;
    int tmp = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] >= '0' && s[j] <= '9') {
        tmp = tmp * 10 + s[j] - '0';
      } else if (s[j] == ',') {
        now.push_back(tmp);
        tmp = 0;
      } else if (s[j] == ':') {
        tmp = 0;
      } else if (s[j] == '-') {
        now.push_back(tmp);
        tmp = 0;
        a[i].push_back(now);
        now.clear();
      }
    }
    for (int j = 0; j < a[i].size(); j++) {
      h[i].push_back(getHash(a[i][j]));
      se[i].insert(h[i][j]);
    }
  }
  for (int i = 1; i <= n; i++) {
    int sum = bp(p, i);
    int sum2 = bp(p2, i);
    for (int j = 0; j < a[i].size(); j++) {
      sum += h[i][j].first;
      sum2 += h[i][j].second;
      if (sum >= mod) sum -= mod;
      if (sum2 >= mod) sum2 -= mod;
    }
    for (int j = 0; j < a[i].size(); j++) {
      sum -= h[i][j].first;
      sum2 -= h[i][j].second;
      if (sum < 0) sum += mod;
      if (sum2 < 0) sum2 += mod;
      int to = -1;
      for (int first : a[i][j]) {
        if (se[first].find(make_pair(sum, sum2)) != se[first].end()) {
          if (to == -1)
            to = first;
          else
            cout << -1, exit(0);
        }
      }
      if (to == -1) cout << -1, exit(0);
      g[i].push_back(to);
      g[to].push_back(i);
      reb++;
      sum += h[i][j].first;
      if (sum >= mod) sum -= mod;
      sum2 += h[i][j].second;
      if (sum2 >= mod) sum2 -= mod;
    }
  }
  dfs(1);
  if (cmp != n || reb != 2 * (n - 1)) cout << -1, exit(0);
  cout << n - 1 << "\n";
  set<pair<int, int> > wtf;
  for (int i = 0; i < n; i++)
    for (int to : g[i]) {
      int a = i, b = to;
      if (a > b) swap(a, b);
      if (wtf.find(make_pair(a, b)) == wtf.end()) {
        wtf.insert(make_pair(a, b));
        cout << a << ' ' << b << "\n";
      }
    }
}
