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;
vector<int> v[1001];
vector<int> t[1001];
unsigned int f[1001][32], nw[32], g[1001][32], F[1001][32], G[1001][32];
int n, d[1001], c[1 << 16], cnt, x, tn, A[1001], An, fa[1001], mi, mii, D[1001];
bool bo[1001], Bo[1001], boo;
bool cmp(int a, int b) { return d[a] < d[b]; }
void del(int j) {
  for (int i = 1; i <= n; i++)
    if ((f[j][i >> 5] >> (i & 31)) & 1) d[i]--;
}
void print(int x, int y) {
  printf("%d %d\n", x, y);
  g[x][y >> 5] |= (1ll << (y & 31));
  g[y][x >> 5] |= (1ll << (x & 31));
}
void dfs(int x) {
  Bo[x] = 0;
  if (d[x] == 3) {
    int po;
    for (int i = 1; i <= n; i++)
      if (bo[i] && ((f[i][x >> 5] >> (x & 31)) & 1)) {
        int cnt = 0;
        for (int j = 0; j < 32; j++)
          cnt += c[f[i][j] & nw[j] & 65535] + c[(f[i][j] & nw[j]) >> 16];
        if (cnt == 3) {
          po = i;
          break;
        }
      }
    int po1 = 0, po2 = 0;
    for (int i = 1; i <= n; i++)
      if (i != x && ((f[po][i >> 5] >> (i & 31)) & 1) &&
          ((nw[i >> 5] >> (i & 31)) & 1)) {
        if (!po1)
          po1 = i;
        else
          po2 = i;
      }
    del(po);
    bo[po] = 0;
    nw[x >> 5] ^= (1ll << (x & 31));
    if (!fa[x]) {
      if ((G[po1][x >> 5] >> (x & 31)) & 1)
        fa[x] = po1;
      else if ((G[po2][x >> 5] >> (x & 31)) & 1)
        fa[x] = po2;
      else if (D[po1] < D[po2])
        fa[x] = po1;
      else
        fa[x] = po2;
      print(x, fa[x]);
    }
    print(po1, po2);
    if (fa[x] == po1)
      fa[po1] = po2;
    else
      fa[po2] = po1;
    if (fa[x]) dfs(fa[x]);
    return;
  }
  mi = (1e9);
  mii = 0;
  for (int i = 1; i <= n; i++)
    if (bo[i] && ((f[i][x >> 5] >> (x & 31)) & 1) &&
        ((f[i][fa[x] >> 5] >> (fa[x] & 31)) & 1)) {
      int cnt = 0;
      for (int j = 0; j < 32; j++)
        cnt += c[f[i][j] & nw[j] & 65535] + c[(f[i][j] & nw[j]) >> 16];
      if (cnt < mi) mi = cnt, mii = i;
    }
  if (mii) {
    for (int i = 0; i < 32; i++) G[fa[x]][i] |= f[mii][i];
    del(mii), bo[mii] = 0;
  }
  nw[x >> 5] ^= (1ll << (x & 31));
}
int main() {
  for (int i = 0; i < (1 << 16); i++) {
    c[i] = 0;
    for (int j = 0; j < 16; j++)
      if ((i >> j) & 1) c[i]++;
  }
  scanf("%d", &n);
  memset(d, 0, sizeof(d));
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 32; j++) f[i][j] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &cnt);
    v[i].clear();
    t[i].clear();
    for (int j = 1; j <= cnt; j++)
      scanf("%d", &x), d[x]++, f[i][x >> 5] |= (1ll << (x & 31));
  }
  cnt = 0;
  for (int j = 0; j < 32; j++) {
    nw[j] = 0;
    for (int k = 0; k < 32; k++) nw[j] |= (1ll << k);
  }
  memset(bo, 1, sizeof(bo));
  memset(Bo, 1, sizeof(Bo));
  for (int i = 1; i <= n; i++)
    if (bo[i]) {
      tn = 0;
      for (int j = 1; j <= n; j++) {
        boo = 1;
        for (int k = 0; k < 32; k++)
          if (f[i][k] ^ f[j][k]) {
            boo = 0;
            break;
          }
        if (boo) continue;
        for (int k = 0; k < 32; k++)
          if ((f[i][k] & f[j][k]) != f[j][k]) {
            boo = 1;
            break;
          }
        if (!boo) {
          tn = -1;
          break;
        }
      }
      if (tn == -1) continue;
      for (int j = i + 1; j <= n; j++)
        if (bo[j]) {
          boo = 1;
          for (int k = 0; k < 32; k++)
            if (f[i][k] ^ f[j][k]) {
              boo = 0;
              break;
            }
          if (boo) tn++, bo[j] = 0;
        }
      if (tn) {
        if (tn == n - 1) {
          for (int i = 2; i <= n; i++) print(1, i);
          return 0;
        }
        An = 0;
        for (int j = 1; j <= n; j++)
          if ((f[i][j >> 5] >> (j & 31)) & 1) A[++An] = j;
        sort(A + 1, A + 1 + An, cmp);
        cnt++;
        for (int j = 1; j <= tn; j++)
          nw[A[j] >> 5] ^= (1ll << (A[j] & 31)), t[cnt].push_back(A[j]);
        for (int j = 0; j < 32; j++) F[cnt][j] = 0;
        for (int j = tn + 1; j <= An; j++)
          F[cnt][A[j] >> 5] |= (1ll << (A[j] & 31)), v[A[j]].push_back(cnt);
      }
    }
  for (int i = 1; i <= n; i++)
    if (!bo[i]) del(i);
  memset(fa, 0, sizeof(fa));
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 32; j++) g[i][j] = G[i][j] = 0;
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= n; i++) D[i] = d[i];
    for (int i = 1; i <= n; i++)
      if (((nw[i >> 5] >> (i & 31)) & 1) && Bo[i] && D[i] == 3) dfs(i);
  }
  int po1 = 0, po2 = 0;
  for (int i = 1; i <= n; i++)
    if (((nw[i >> 5] >> (i & 31)) & 1) && d[i] == 2) {
      if (!po1)
        po1 = i;
      else
        po2 = i;
    }
  if (po2) print(po1, po2);
  memset(bo, 1, sizeof(bo));
  for (int i = 1, sz; i <= n; i++) {
    sz = v[i].size();
    g[i][i >> 5] |= (1ll << (i & 31));
    for (int j = 0; j < sz; j++)
      if (bo[v[i][j]]) {
        x = v[i][j];
        boo = 1;
        for (int k = 0; k < 32; k++)
          if (F[x][k] != g[i][k]) {
            boo = 0;
            break;
          }
        if (boo) {
          int siz = t[x].size();
          bo[x] = 0;
          for (int k = 0; k < siz; k++) print(i, t[x][k]);
          break;
        }
      }
  }
  return 0;
}