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 int MaxN = 1010;
class Bitset {
 public:
  static const int Bit = 30, Sz = MaxN / Bit + 1;
  int c[Sz];
  Bitset() { memset(c, 0, sizeof c); }
  void set(int x) { c[x / Bit] |= (1 << (x % Bit)); }
  friend Bitset operator&(const Bitset &a, const Bitset &b) {
    Bitset ret;
    for (int i = 0; i < Sz; ++i) ret.c[i] = a.c[i] & b.c[i];
    return ret;
  }
  int size() const {
    int ret = 0;
    for (int i = 0; i < Sz; ++i) ret += __builtin_popcount(c[i]);
    return ret;
  }
  vector<int> to_vint() const {
    vector<int> ret;
    for (int i = 0; i < Sz; ++i)
      if (c[i]) {
        int x = c[i];
        while (x) {
          int u = x & -x;
          ret.push_back(i * Bit + 31 - __builtin_clz(u));
          x ^= u;
        }
      }
    return ret;
  }
} f[MaxN];
int n;
vector<int> G[MaxN], tree[MaxN];
set<pair<int, int> > ans;
bool to_ans(int u, int v) {
  if (u > v) swap(u, v);
  return (ans.insert(make_pair(u, v))).second;
}
int deg[MaxN];
bool done[MaxN], edge[MaxN][MaxN], rem[MaxN];
int cnt[MaxN], used[MaxN];
bool cmp_size(const int &a, const int &b) {
  return G[a].size() < G[b].size();
  return 0;
}
bool subset(const vector<int> &a, const vector<int> &b) {
  static int tm[MaxN], tot = 0;
  ++tot;
  for (auto i : b) tm[i] = tot;
  for (auto i : a)
    if (tm[i] != tot) return 0;
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int u;
      scanf("%d", &u);
      G[i].push_back(u);
      f[i].set(u);
    }
  }
  int sz = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j < i; ++j) {
      Bitset t = f[i] & f[j];
      if (t.size() == 2) {
        vector<int> edge = t.to_vint();
        if (!to_ans(edge[0], edge[1])) continue;
        tree[edge[0]].push_back(edge[1]);
        tree[edge[1]].push_back(edge[0]);
        ++deg[edge[0]];
        ++deg[edge[1]];
        ++sz;
      }
    }
  if (sz == 0) {
    for (int i = 2; i <= n; ++i) printf("1 %d\n", i);
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    if (deg[i]) done[i] = 1;
  for (int i = 1; i <= n; ++i)
    for (auto j : G[i]) {
      edge[i][j] = 1;
      if (deg[j]) ++cnt[i];
    }
  while (sz > 1) {
    int v = 0;
    for (int i = 1; i <= n; ++i)
      if (deg[i] == 1 && !rem[i]) v = i;
    for (int i = 1; i <= n; ++i)
      if (!used[i] && cnt[i] == 2 && edge[i][v]) {
        for (auto j : G[i])
          if (!done[j]) {
            to_ans(j, v);
            done[j] = 1;
          }
        used[i] = 1;
      }
    for (auto u : tree[v]) --deg[u];
    for (int i = 1; i <= n; ++i)
      if (!used[i] && edge[i][v]) --cnt[i];
    rem[v] = 1;
    --sz;
  }
  int con = 0, u = 0, v = 0;
  for (int i = 1; i <= n; ++i) {
    if (!done[i]) ++con;
    if (!deg[i] || rem[i]) continue;
    if (u)
      v = i;
    else
      u = i;
  }
  static int h[MaxN];
  int htot = 0;
  for (int i = 1; i <= n; ++i)
    if (!used[i]) h[++htot] = i;
  sort(h + 1, h + htot + 1, cmp_size);
  int tmp = htot;
  htot = 0;
  for (int i = 1; i <= tmp; ++i) {
    bool flag = 1;
    for (int j = 1; j < i && flag; ++j)
      if (subset(G[h[j]], G[h[i]])) flag = 0;
    if (flag) swap(h[++htot], h[i]);
  }
  for (int i = htot + 1; i <= tmp; ++i) h[i] = 0;
  bool flag = 1;
  for (auto i : tree[u]) {
    flag &= edge[h[1]][i];
  }
  if (htot >= 2)
    for (auto i : tree[v]) flag &= edge[h[2]][i];
  if (flag) {
    for (auto i : G[h[1]])
      if (!done[i]) to_ans(i, u);
    for (auto i : G[h[2]])
      if (!done[i]) to_ans(i, v);
  } else {
    for (auto i : G[h[2]])
      if (!done[i]) to_ans(i, u);
    for (auto i : G[h[1]])
      if (!done[i]) to_ans(i, v);
  }
  for (auto i : ans) printf("%d %d\n", i.first, i.second);
  return 0;
}