#include <bits/stdc++.h>
using namespace std;
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1005;
vector<int> adj[N];
unsigned long long a[N];
unsigned long long val[N][N];
unsigned long long sum;
int n;
bool vis[N];
int getint(string &s) {
  int res = 0;
  while (s.size() > 0 && '0' <= s.back() && s.back() <= '9') {
    res = 10 * res + s.back() - '0';
    s.pop_back();
  }
  if (s.size() > 0) s.pop_back();
  return res;
}
unsigned long long dfs(int u, int p) {
  unsigned long long res = a[u];
  vis[u] = true;
  for (int v : adj[u])
    if (v != p) {
      if (vis[v]) {
        cout << -1;
        exit(0);
      }
      res ^= dfs(v, u);
    }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    a[i] = rd();
    sum ^= a[i];
  }
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    while (s.size() > 0) {
      unsigned long long res = 0;
      vector<int> t;
      int m = getint(s);
      for (int j = 1; j <= m; j++) {
        int id = getint(s);
        res ^= a[id];
        t.push_back(id);
      }
      for (int j : t) val[i][j] = res;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      if ((val[i][j] ^ val[j][i]) == sum) {
        adj[i].push_back(j);
        adj[j].push_back(i);
      }
  dfs(1, -1);
  for (int i = 2; i <= n; i++)
    if (!vis[i]) return cout << -1, 0;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof(vis));
    for (int j : adj[i])
      if (dfs(j, i) != val[i][j]) return cout << -1, 0;
  }
  cout << n - 1 << "\n";
  for (int i = 1; i <= n; i++)
    for (int j : adj[i])
      if (i < j) cout << i << " " << j << "\n";
  return 0;
}
