Problem: Archaeologists found some information about an ancient land of Treeland. We know for sure that the Treeland consisted of n cities connected by the n - 1 road, such that you can get from each city to any other one along the roads. However, the information about the specific design of roads in Treeland has been lost. The only thing that the archaeologists can use is the preserved information about near cities.

Two cities of Treeland were called near, if it were possible to move from one city to the other one by moving through at most two roads. Also, a city is considered near to itself. During the recent excavations archaeologists found a set of n notes, each of them represents a list of cities, near to some of the n cities of the country. However, unfortunately, none of the found records lets you understand in what order the cities go in the list and for which city in the list the near to it cities were listed. 

Help the archaeologists and restore any variant of the map of Treeland that meets the found information.

Input

The first line contains integer n (2 ≤ n ≤ 1000) — the number of cities in the country. 

Next n lines describe the found lists of near cities. Each list starts from number k (1 ≤ k ≤ n), representing the number of cities in the list followed by k city numbers. All numbers in each list are distinct.

It is guaranteed that the given information determines at least one possible road map.

Output

Print n - 1 pairs of numbers representing the roads of the country. The i-th line must contain two integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), showing that there is a road between cities ai and bi.

The answer you print must satisfy the description of close cities from the input. You may print the roads of the countries in any order. The cities that are connected by a road may also be printed in any order.

If there are multiple good answers, you may print any of them.

Examples

Input

5
4 3 2 4 1
5 5 3 2 4 1
5 4 2 1 5 3
4 2 1 4 3
3 1 4 5


Output

1 4
1 2
1 3
4 5


Input

6
5 6 1 3 4 2
5 2 1 3 4 6
6 3 6 2 5 4 1
6 6 1 2 5 3 4
3 5 2 4
5 3 1 2 4 6


Output

2 4
1 2
2 3
2 6
4 5

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const long long N = 1007;
vector<vector<long long> > gr;
bitset<N> all[N];
const long long INF = 1e9 + 7;
long long n;
bool check(vector<vector<long long> > tree) {
  vector<vector<long long> > gr1(n, vector<long long>(n, 0));
  for (long long v = 0; v < n; v++) {
    for (long long u : tree[v]) {
      gr1[v][u] = 1;
      for (long long x : tree[u]) {
        gr1[v][x] = 1;
      }
    }
  }
  return gr == gr1;
}
signed main() {
  cin >> n;
  gr.resize(n, vector<long long>(n, 0));
  for (long long i = 0; i < n; i++) {
    long long k;
    cin >> k;
    for (long long j = 0; j < k; j++) {
      long long v;
      cin >> v;
      v--;
      gr[i][v] = 1;
      all[i][v] = 1;
    }
  }
  vector<pair<long long, long long> > res;
  vector<bool> used(n, false);
  for (long long v = 0; v < n; v++) {
    bitset<N> now, s;
    for (long long i = 0; i < N; i++) {
      now[i] = 1;
    }
    s = now;
    long long cnt = 0;
    for (long long u = 0; u < n; u++) {
      if (!gr[u][v]) continue;
      now &= all[u];
      cnt++;
    }
    if (cnt != now.count()) continue;
    if (cnt == n) {
      for (long long j = 2; j <= n; j++) {
        cout << 1 << " " << j << "\n";
      }
      exit(0);
    }
    long long ban = -1;
    for (long long u = 0; u < n; u++) {
      if (gr[u][v]) continue;
      auto nowt = all[u] & now;
      if (!nowt.count()) continue;
      if (nowt.count() > 2) {
        assert(false);
      }
      if (nowt.count() == 2) {
        s &= nowt;
      } else {
        if (ban != -1) continue;
        for (long long k = 0; k < N; k++) {
          if (nowt[k]) {
            ban = k;
            break;
          }
        }
      }
    }
    vector<long long> t;
    for (long long j = 0; j < N; j++) {
      if (s[j]) {
        t.push_back(j);
      }
    }
    long long need = 0;
    assert(s.count() < 3);
    if (t.size() == 1) {
      need = t[0];
    } else {
      if (ban != -1) {
        need = t[0] + t[1] - ban;
      } else {
        need = t[0];
      }
    }
    bitset<N> masks[N];
    vector<long long> p(n, -1);
    queue<long long> q;
    res.push_back({need, v});
    p[need] = v;
    masks[v] = now;
    masks[need] = now;
    for (long long j = 0; j < n; j++) {
      if (now[j]) {
        used[j] = true;
        if (j == v || j == need) continue;
        res.push_back({j, need});
        q.push(j);
        p[j] = need;
      }
    }
    while (!q.empty()) {
      long long x = q.front();
      q.pop();
      bitset<N> ones;
      for (long long j = 0; j < N; j++) {
        ones[j] = 1;
      }
      long long sons = 0;
      for (long long j = 0; j < n; j++) {
        if (!gr[j][x] || !gr[j][p[x]] || gr[j][p[p[x]]]) continue;
        auto kek = masks[p[x]] & all[j];
        if (kek.count() != 2) continue;
        ones &= all[j];
        sons++;
      }
      if (sons > 1) {
        assert(sons == ones.count() - 2);
        for (long long j = 0; j < n; j++) {
          if (!ones[j] || j == x || j == p[x]) continue;
          q.push(j);
          p[j] = x;
          res.push_back({j, x});
        }
        masks[x] = ones;
      } else if (sons == 1) {
        bitset<N> mask;
        for (long long j = 0; j < N; j++) {
          mask[j] = 0;
        }
        mask[x] = 1;
        mask[p[x]] = 1;
        long long last = -1;
        for (long long j = 0; j < n; j++) {
          if (!gr[j][x] || !gr[j][p[x]] || !gr[j][p[p[x]]]) continue;
          auto kek = all[j] & ones;
          if (kek.count() == 3) {
            for (long long k = 0; k < n; k++) {
              if (kek[k] && k != x && k != p[x]) {
                last = k;
                break;
              }
            }
            break;
          }
        }
        assert(last != -1);
        mask[last] = 1;
        masks[x] = mask;
        p[last] = x;
        q.push(last);
        res.push_back({last, x});
      }
    }
    for (auto p : res) {
      cout << p.first + 1 << " " << p.second + 1 << "\n";
    }
    exit(0);
  }
}