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;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
const int N = 1005;
unsigned long long ALL;
struct Bs {
  unsigned long long a[16];
  inline int get(int p) { return a[p >> 6] >> (p & 63) & 1; }
  inline void add(int p) { a[p >> 6] |= 1ull << (p & 63); }
  inline void del(int p) { a[p >> 1] &= ALL ^ (1ull << (p & 63)); }
  inline void And(Bs &S) {
    a[0] &= S.a[0], a[1] &= S.a[1], a[2] &= S.a[2], a[3] &= S.a[3],
        a[4] &= S.a[4], a[5] &= S.a[5], a[6] &= S.a[6], a[7] &= S.a[7];
    a[8] &= S.a[8], a[9] &= S.a[9], a[10] &= S.a[10], a[11] &= S.a[11],
        a[12] &= S.a[12], a[13] &= S.a[13], a[14] &= S.a[14], a[15] &= S.a[15];
  }
  inline void Or(Bs &S) {
    a[0] |= S.a[0], a[1] |= S.a[1], a[2] |= S.a[2], a[3] |= S.a[3],
        a[4] |= S.a[4], a[5] |= S.a[5], a[6] |= S.a[6], a[7] |= S.a[7];
    a[8] |= S.a[8], a[9] |= S.a[9], a[10] |= S.a[10], a[11] |= S.a[11],
        a[12] |= S.a[12], a[13] |= S.a[13], a[14] |= S.a[14], a[15] |= S.a[15];
  }
  inline void Xor(Bs &S) {
    a[0] ^= S.a[0], a[1] ^= S.a[1], a[2] ^= S.a[2], a[3] ^= S.a[3],
        a[4] ^= S.a[4], a[5] ^= S.a[5], a[6] ^= S.a[6], a[7] ^= S.a[7];
    a[8] ^= S.a[8], a[9] ^= S.a[9], a[10] ^= S.a[10], a[11] ^= S.a[11],
        a[12] ^= S.a[12], a[13] ^= S.a[13], a[14] ^= S.a[14], a[15] ^= S.a[15];
  }
  inline void readd() {
    int t, x;
    read(t);
    while (t--) read(x), add(x);
  }
} all;
bool operator==(const Bs &a, const Bs &b) {
  return a.a[0] == b.a[0] && a.a[1] == b.a[1] && a.a[2] == b.a[2] &&
         a.a[3] == b.a[3] && a.a[4] == b.a[4] && a.a[5] == b.a[5] &&
         a.a[6] == b.a[6] && a.a[7] == b.a[7] && a.a[8] == b.a[8] &&
         a.a[9] == b.a[9] && a.a[10] == b.a[10] && a.a[11] == b.a[11] &&
         a.a[12] == b.a[12] && a.a[13] == b.a[13] && a.a[14] == b.a[14] &&
         a.a[15] == b.a[15];
}
int bit[1 << 22], lowb[1 << 22], siz[1 << 22];
int n;
Bs s[N], tmp;
inline int Cnt(unsigned long long x) {
  static int tot;
  tot = 0;
  while (x) tot += siz[x & 4194303], x >>= 22;
  return tot;
}
inline int Cnt(Bs &a) {
  static int tot, i;
  static unsigned long long x;
  for (i = tot = 0; i < 16; ++i) {
    x = a.a[i];
    while (x) tot += siz[x & 4194303], x >>= 22;
  }
  return tot;
}
int cnte, ex[N], ey[N], tp[N];
vector<int> G[N];
int d[N][N];
Bs all1, a[N], b[N];
inline void get(Bs &a) {
  static int i;
  static unsigned long long x;
  static int u, t, off;
  u = -1, off = 0;
  for (i = 0; i < 16; ++i)
    if (x = a.a[i]) {
      off = i << 6;
      while (x) {
        while (x & 4194303) {
          t = off + bit[lowb[x & 4194303]];
          if (u == -1)
            u = t;
          else {
            d[u][t] = d[t][u] = tp[u] = tp[t] = 1;
            G[u].push_back(t), G[t].push_back(u);
            return;
          }
          x ^= lowb[x & 4194303];
        }
        x >>= 22, off += 22;
      }
    }
}
int main() {
  int i, j;
  for (i = 0; i < 64; ++i) ALL |= 1ull << i;
  for (i = 0; i < 22; ++i) bit[1 << i] = i;
  for (i = 0; i < 1 << 22; ++i) siz[i] = siz[i >> 1] + (i & 1);
  for (i = 0; i < 1 << 22; ++i) lowb[i] = i & -i;
  read(n);
  for (i = 1; i <= n; ++i) s[i].readd();
  if (n == 2) {
    puts("1 2");
    return 0;
  }
  if (n == 3) {
    puts("1 2\n2 3");
    return 0;
  }
  for (i = 1; i <= n; ++i)
    for (j = i + 1; j <= n; ++j) {
      tmp = s[i], tmp.And(s[j]);
      if (Cnt(tmp) ^ 2) continue;
      get(tmp);
    }
  int cnt1 = 0;
  for (i = 1; i <= n; ++i) cnt1 += tp[i] ? 1 : 0;
  if (!cnt1) {
    for (i = 2; i <= n; ++i) printf("1 %d\n", i);
    return 0;
  }
  if (cnt1 == 1) {
    int x = -1;
    for (i = 1; i <= n; ++i)
      if (tp[i]) {
        x = i;
        break;
      }
    for (i = 1; i <= n; ++i)
      if (!tp[i]) {
        write(i), putchar(' '), write(x), putchar('\n');
      }
    return 0;
  }
  if (cnt1 == 2) {
    int x = -1, y = -1;
    for (i = 1; i <= n; ++i)
      if (tp[i]) {
        if (x == -1)
          x = i;
        else
          y = i;
      } else
        tp[i] = 2;
    for (i = 1; i <= n; ++i)
      if (Cnt(s[i]) < n) {
        for (j = 1; j <= n; ++j)
          if (s[i].get(j) && tp[j] == 2) tp[j] = 3;
        break;
      }
    write(x), putchar(' '), write(y), putchar('\n');
    for (i = 1; i <= n; ++i)
      if (tp[i] != 1)
        write(i), putchar(' '), write(tp[i] == 2 ? x : y), putchar('\n');
    return 0;
  }
  for (i = 1; i <= n; ++i)
    if (tp[i]) all1.add(i);
  for (i = 1; i <= n; ++i) all.add(i);
  for (i = 1; i <= n; ++i)
    if (!tp[i])
      for (a[i] = all, j = 1; j <= n; ++j)
        if (s[j].get(i) && Cnt(s[j]) < Cnt(a[i])) a[i] = s[j];
  cnte = 0;
  for (i = 1; i <= n; ++i)
    for (j = i + 1; j <= n; ++j)
      if (d[i][j]) ++cnte, ex[cnte] = i, ey[cnte] = j;
  for (i = 1; i <= n; ++i)
    if (tp[i])
      for (b[i].add(i), j = 0; j < G[i].size(); ++j) b[i].add(G[i][j]);
  for (i = 1; i <= cnte; ++i)
    write(ex[i]), putchar(' '), write(ey[i]), putchar('\n');
  for (i = 1; i <= n; ++i)
    if (!tp[i]) {
      a[i].And(all1);
      for (j = 1; j <= n; ++j)
        if (tp[j] && a[i] == b[j]) {
          write(i), putchar(' '), write(j), putchar('\n');
          break;
        }
    }
  return 0;
}