#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f2f1f0f;
const int MAX_N = 1e3 + 100;
int N, Ix[MAX_N][MAX_N], All[MAX_N];
vector<int> Sz[MAX_N];
vector<vector<int>> List[MAX_N];
vector<vector<int>> My[MAX_N];
vector<int> Ed[MAX_N];
bool Vis[MAX_N];
vector<pair<int, int>> Ans;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int cnt = 0, ix = 0;
    while (cnt < N - 1) {
      if (ix != 0) scanf("-");
      int k;
      scanf("%d", &k);
      scanf(":");
      Sz[i].push_back(k);
      cnt += k;
      List[i].push_back(vector<int>());
      for (int j = 0; j < k; j++) {
        if (j != 0) scanf(",");
        int x;
        scanf("%d", &x);
        Ix[i][x] = ix;
        List[i].back().push_back(x);
      }
      ix++;
    }
    All[i] = ix;
  }
  vector<int> cnt(N + 1, 0);
  for (int i = 1; i <= N; i++)
    for (int j = i + 1; j <= N; j++) {
      int all = 0;
      for (int x : List[i][Ix[i][j]]) cnt[x]++, all++;
      bool isCan = true;
      for (int y : List[j][Ix[j][i]]) {
        cnt[y]++, all++;
        if (cnt[y] == 2) isCan = false;
      }
      if (isCan && all == N)
        Ans.push_back(pair<int, int>(i, j)), Ed[i].push_back(j),
            Ed[j].push_back(i);
      for (int y : List[j][Ix[j][i]]) cnt[y]--;
      for (int x : List[i][Ix[i][j]]) cnt[x]--;
    }
  if (((int)(Ans).size()) != N - 1) {
    puts("-1");
    return 0;
  } else {
    for (int i = 1; i <= N; i++) {
      vector<bool> vis(N + 1, false);
      vis[i] = true;
      for (int l = 0; l < ((int)(Ed[i]).size()); l++) {
        My[i].push_back(vector<int>());
        queue<int> Q;
        Q.push(Ed[i][l]);
        vis[Ed[i][l]] = true;
        while (!Q.empty()) {
          int v = Q.front();
          Q.pop();
          My[i].back().push_back(v);
          for (int w : Ed[v])
            if (vis[w] == false) Q.push(w), vis[w] = true;
        }
      }
      for (vector<int> &v : List[i]) sort((v).begin(), (v).end());
      for (vector<int> &v : My[i]) sort((v).begin(), (v).end());
      sort((List[i]).begin(), (List[i]).end());
      sort((My[i]).begin(), (My[i]).end());
      if (List[i] != My[i]) {
        puts("-1");
        return 0;
      }
    }
  }
  printf("%d\n", ((int)(Ans).size()));
  for (pair<int, int> &e : Ans) printf("%d %d\n", e.first, e.second);
  return 0;
}
