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 N = 1050, W = 31;
template <class T>
void read(T &x) {
  int sgn = 1;
  char ch;
  x = 0;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') ch = getchar(), sgn = -1;
  for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  x *= sgn;
}
template <class T>
void write(T x) {
  if (x < 0)
    putchar('-'), write(-x);
  else if (x < 10)
    putchar(x + '0');
  else
    write(x / 10), putchar(x % 10 + '0');
}
int n, adj[N][N / W];
bool leaf[N], g[N][N], t[N][N], vis[N];
inline int lowbit(int x) { return x & -x; }
int popcount(int x) { return x ? popcount(x ^ lowbit(x)) + 1 : 0; }
int main() {
  read(n);
  if (n == 2) {
    puts("1 2");
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= (n - 1) / W; j++) adj[i][j] = 0;
  }
  for (int i = 0; i < n; i++) {
    int k;
    read(k);
    for (int j = 0; j < n; j++) g[i][j] = t[i][j] = false;
    for (int j = 1; j <= k; j++) {
      int u;
      read(u), u--;
      adj[u][i / W] |= (1 << (i % W));
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int cnt = 0;
      for (int k = 0; k <= (n - 1) / W; k++) {
        cnt += popcount(adj[i][k] & adj[j][k]);
        if (cnt >= 3) break;
      }
      if (cnt >= 3) g[i][j] = g[j][i] = true;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= (n - 1) / W; j++) adj[i][j] = 0;
    adj[i][i / W] |= (1 << (i % W));
    for (int j = 0; j < n; j++) {
      if (g[i][j]) adj[i][j / W] |= (1 << (j % W));
    }
  }
  for (int i = 0; i < n; i++) leaf[i] = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      int cnt = 0;
      for (int k = 0; k <= (n - 1) / W; k++) {
        cnt += popcount(adj[i][k] & adj[j][k]);
        if (cnt >= 3) break;
      }
      if (cnt == 2) {
        vector<int> tmp;
        for (int k = 0; k <= (n - 1) / W; k++) {
          int x = adj[i][k] & adj[j][k];
          if (!x) continue;
          for (int l = 0; l < W; l++) {
            if (x >> l & 1) tmp.push_back(W * k + l);
          }
        }
        leaf[tmp[0]] = leaf[tmp[1]] = false;
        t[tmp[0]][tmp[1]] = t[tmp[1]][tmp[0]] = true;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt += (!leaf[i]);
  if (cnt == 0) {
    for (int i = 1; i < n; i++) t[0][i] = t[i][0] = true;
  } else if (cnt == 2) {
    vector<int> vec_l, vec;
    for (int i = 0; i < n; i++) {
      if (leaf[i])
        vec_l.push_back(i);
      else
        vec.push_back(i);
    }
    t[vec[0]][vec_l[0]] = t[vec_l[0]][vec[0]] = true;
    for (int i = 1; i < vec_l.size(); i++) {
      if (adj[vec_l[0]][vec_l[i] / W] >> (vec_l[i] % W) & 1)
        t[vec[0]][vec_l[i]] = t[vec_l[i]][vec[0]] = true;
      else
        t[vec[1]][vec_l[i]] = t[vec_l[i]][vec[1]] = true;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (leaf[i]) {
        vector<int> vec;
        for (int j = 0; j < n; j++) {
          vis[j] = false;
          if (!leaf[j] && (adj[i][j / W] >> (j % W) & 1)) vec.push_back(j);
        }
        bool chk = true;
        for (int j = 1; j < vec.size(); j++) vis[vec[j]] = true;
        for (int j = 0; j < n; j++) {
          if (!leaf[j] && t[vec[0]][j] && !vis[j]) chk = false;
        }
        for (int j = 1; j < vec.size(); j++) {
          if (!t[vec[0]][vec[j]]) chk = false;
        }
        if (chk)
          t[vec[0]][i] = t[i][vec[0]] = true;
        else {
          for (int j = 1; j < vec.size(); j++) {
            if (!leaf[vec[j]] && t[vec[0]][vec[j]])
              t[vec[j]][i] = t[i][vec[j]] = true;
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (t[i][j]) {
        write(i + 1), putchar(' ');
        write(j + 1), putchar('\n');
      }
    }
  }
  return 0;
}