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;
namespace zyt {
template <typename T>
inline bool read(T &x) {
  char c;
  bool f = false;
  x = 0;
  do c = getchar();
  while (c != EOF && c != '-' && !isdigit(c));
  if (c == EOF) return false;
  if (c == '-') f = true, c = getchar();
  do x = x * 10 + c - '0', c = getchar();
  while (isdigit(c));
  if (f) x = -x;
  return true;
}
template <typename T>
inline void write(T x) {
  static char buf[20];
  char *pos = buf;
  if (x < 0) putchar('-'), x = -x;
  do *pos++ = x % 10 + '0';
  while (x /= 10);
  while (pos > buf) putchar(*--pos);
}
const int N = 1e3 + 10;
int n, d[N];
bool vis[N][N];
class bitset {
 private:
  const static int B = 32, BB = 5;
  unsigned data[N / B + 10];
  int len, n;
  static int ct[1 << (B >> 1)];
  static bool flag;

 public:
  bitset(const int _n = 0) : n(_n) {
    memset(data, 0, sizeof(data));
    len = (n >> BB) + 1;
    if (!flag) {
      flag = true;
      for (int i = 0; i < (1 << (B >> 1)); i++) ct[i] = ct[i >> 1] + (i & 1);
    }
  }
  void set(const int p) { data[p >> BB] |= (1U << (p & (B - 1))); }
  void reset(const int p) { data[p >> BB] &= ~(1U << (p & (B - 1))); }
  bool operator[](const unsigned p) const {
    return data[p >> BB] & (1U << (p & (B - 1)));
  }
  bitset operator&(const bitset &b) const {
    bitset ans(n);
    for (int i = 0; i < len; i++) ans.data[i] = (data[i] & b.data[i]);
    return ans;
  }
  int count() const {
    int ans = 0;
    for (int i = 0; i < len; i++)
      ans += ct[data[i] >> (B >> 1)] + ct[data[i] & ((1 << (B >> 1)) - 1)];
    return ans;
  }
  int first() const {
    for (int i = 0; i < len; i++)
      if (data[i]) {
        int ans = (i << BB), tmp = data[i];
        while (!(tmp & 1)) tmp >>= 1, ++ans;
        return ans;
      }
  }
} bs[N];
int bitset::ct[1 << (bitset::B >> 1)];
bool bitset::flag;
pair<int, int> e[N];
int work() {
  read(n);
  for (int i = 1; i <= n; i++) {
    int k;
    read(k);
    bs[i] = bitset(n);
    while (k--) {
      int a;
      read(a);
      bs[i].set(a);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) {
      bitset tmp = (bs[i] & bs[j]);
      if (tmp.count() == 2) {
        int a = tmp.first();
        tmp.reset(a);
        int b = tmp.first();
        if (!vis[a][b]) {
          printf("%d %d\n", a, b);
          e[cnt++] = pair<int, int>(a, b);
          ++d[a], ++d[b];
          vis[a][b] = vis[b][a] = true;
        }
      }
    }
  if (!cnt) {
    for (int i = 2; i <= n; i++) printf("%d %d\n", 1, i);
  } else if (cnt == 1) {
    for (int i = 1; i <= n; i++)
      if (bs[i].count() < n) {
        for (int j = 1; j <= n; j++)
          if (!d[j]) {
            if (bs[i][j])
              printf("%d %d\n", e[0].first, j);
            else
              printf("%d %d\n", e[0].second, j);
          }
        break;
      }
  } else {
    for (int i = 1; i <= n; i++)
      if (!d[i]) {
        static int deg[N];
        bitset b(n);
        bool flag = false;
        memset(deg, 0, sizeof(int[n + 1]));
        for (int j = 1; j <= n; j++)
          if (bs[j][i]) {
            if (flag)
              b = (b & bs[j]);
            else
              b = bs[j], flag = true;
          }
        for (int j = 0; j < cnt; j++)
          if (b[e[j].first] && b[e[j].second])
            ++deg[e[j].first], ++deg[e[j].second];
        int c = 0;
        for (int j = 1; j <= n; j++)
          if (d[j] && b[j]) ++c;
        for (int j = 1; j <= n; j++)
          if (b[j]) {
            if (c == 2) {
              if (d[j] == 1) printf("%d %d\n", i, j);
            } else {
              if (deg[j] > 1) printf("%d %d\n", i, j);
            }
          }
      }
  }
  return 0;
}
}  // namespace zyt
int main() { return zyt::work(); }