#include <bits/stdc++.h>   using namespace std;   char buff[100000], *pb;   int readInt() {     int num = 0;     while (*pb && isdigit(*pb)) {       num = num * 10 + (*pb -  0 );       ++pb;     }     return num;   }   int nextChar() {     int c =   0 ;     if (*pb) {       c = *pb;       pb++;     }     return c;   }   int hasNext() { return *pb ? 1 : 0; }   int main(void) {     int n;     scanf( %i n , &n);     int nextId = 1;     map<vector<int>, int> SId;     vector<int> deg(n + 1);     vector<vector<vector<int>>> S(n + 1);     vector<vector<int>> H(n + 1);     for (int i = 1; i <= n; i++) {       scanf( %s , buff);       pb = buff;       while (hasNext()) {         int k = readInt();         assert(nextChar() ==  : );         vector<int> s;         while (hasNext()) {           s.push_back(readInt());           if (nextChar() ==  - ) {             break;           }         }         assert(s.size() == k);         sort(begin(s), end(s));         S[i].push_back(s);         deg[i]++;         if (!SId.count(s)) {           SId[s] = nextId++;         }         H[i].push_back(SId[s]);       }     }     vector<vector<int>> sh = H;     for (vector<int> &s : sh) {       sort(s.begin(), s.end());     }     vector<int> from, to;     vector<int> proc(n + 1);     queue<int> Q;     for (int i = 1; i <= n; i++) {       if (deg[i] == 1) {         proc[i] = 1;         Q.push(i);       }     }     vector<int> tree_deg(n + 1);     map<int, int> root;     set<int> seen;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       vector<int> sub = {u};       for (int j = 0; j < H[u].size(); j++) {         int id = H[u][j];         if (seen.count(id)) {           from.push_back(u);           to.push_back(root[id]);           tree_deg[root[id]]++;           for (auto e : S[u][j]) {             sub.push_back(e);           }         }       }       sort(begin(sub), end(sub));       int id = SId[sub];       seen.insert(id);       root[id] = u;       for (int i = 1; i <= n; i++)         if (!proc[i]) {           if (binary_search(begin(sh[i]), end(sh[i]), id)) {             deg[i]--;             if (deg[i] <= 1) {               proc[i] = 1;               Q.push(i);             }           }         }     }     bool ok = true;     for (int d : tree_deg) {       if (d > 1) {         ok = false;       }     }     if (ok && int(from.size()) == n - 1) {       printf( %i n , n - 1);       for (int i = 0; i < n - 1; i++) {         printf( %i %i n , from[i], to[i]);       }     } else {       puts( -1 );     }     return 0;   }   