#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int N;
vector<set<int> > adj[MAXN];
vector<set<int> > adj2[MAXN];
int branch[MAXN][MAXN];
vector<int> adj3[MAXN];
vector<pair<int, int> > E[MAXN];
int cnt[MAXN];
vector<pair<int, int> > ans;
queue<int> q;
bool in_queue[MAXN];
void dfs(int cur, int prev, int root, int idx) {
  adj2[root][idx].erase(cur);
  for (int i = 0; i < adj3[cur].size(); i++) {
    int next = adj3[cur][i];
    if (next == prev) continue;
    dfs(next, cur, root, idx);
  }
}
bool check() {
  for (int i = 0; i < N - 1; i++) {
    adj3[ans[i].first].push_back(ans[i].second);
    adj3[ans[i].second].push_back(ans[i].first);
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < adj3[i].size(); j++) {
      int k = adj3[i][j];
      dfs(k, i, i, branch[i][k]);
      if (!adj2[i][branch[i][k]].empty()) return false;
    }
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> N;
  for (int i = 1; i <= N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < s.size();) {
      int k = j, num = 0;
      for (; s[k] != ':'; k++) num = 10 * num + s[k] - '0';
      k++;
      adj[i].push_back(set<int>());
      adj2[i].push_back(set<int>());
      cnt[i]++;
      while (true) {
        int cur = 0;
        for (; k < s.size() && s[k] != '-' && s[k] != ','; k++)
          cur = 10 * cur + s[k] - '0';
        adj[i].back().insert(cur);
        adj2[i].back().insert(cur);
        branch[i][cur] = adj[i].size() - 1;
        E[cur].push_back(make_pair(i, adj[i].size() - 1));
        if (k == s.size() || s[k] == '-') break;
        k++;
      }
      j = k + 1;
    }
    if (cnt[i] == 1) {
      q.push(i);
      in_queue[i] = true;
    }
  }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    if (cnt[cur] == 0) continue;
    bool alreadyConnected = false;
    for (int i = 0; i < E[cur].size(); i++) {
      int next = E[cur][i].first, idx = E[cur][i].second;
      adj[next][idx].erase(cur);
      if (adj[next][idx].empty()) {
        cnt[next]--;
        if (alreadyConnected) {
          cout << "-1\n";
          return 0;
        }
        alreadyConnected = true;
        ans.push_back(make_pair(cur, next));
        if (cnt[next] == 1 && !in_queue[next]) q.push(next);
      }
    }
  }
  if (ans.size() == N - 1 && check()) {
    cout << N - 1 << "\n";
    for (int i = 0; i < N - 1; i++)
      cout << ans[i].first << " " << ans[i].second << "\n";
  } else
    cout << "-1\n";
  return 0;
}
