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 <class T>
inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int N = 1010;
int nxt[N][N], num[N][N], n;
int find(int p, int x) {
  return nxt[p][x] == x ? x : nxt[p][x] = find(p, nxt[p][x]);
}
int b[N], vis[N];
vector<pair<int, int> > G[N];
int col[N];
void dfs(int u, int c) {
  col[u] = c;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i].first;
    if (!~col[v]) dfs(v, c ^ G[u][i].second);
  }
}
int main() {
  rd(n);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n + 1; ++j) nxt[i][j] = j;
  }
  for (int i = 1; i <= n; ++i) {
    int m;
    rd(m);
    for (int j = 1; j <= m; ++j) rd(b[j]), vis[b[j]] = 1;
    for (int j = 1; j <= m; ++j) {
      int u = b[j];
      for (int k = find(u, 1); k <= n; k = find(u, k + 1))
        if (vis[k]) {
          num[u][k]++;
          if (num[u][k] == 3) nxt[u][k] = k + 1;
        }
    }
    for (int j = 1; j <= m; ++j) vis[b[j]] = 0;
  }
  if (n == 2) {
    printf("1 2\n");
    return 0;
  }
  int f5 = 0;
  for (int i = 1; i <= n && !f5; ++i)
    for (int j = 1; j <= n && !f5; ++j)
      if (num[i][j] == 0) f5 = 1;
  if (!f5) {
    int f4 = 0;
    for (int i = 1; i <= n && !f4; ++i)
      for (int j = 1; j <= n && !f4; ++j)
        if (num[i][j] == 1) f4 = 1;
    if (!f4) {
      int f3 = 0;
      for (int i = 1; i <= n && !f3; ++i)
        for (int j = 1; j <= n && !f3; ++j)
          if (num[i][j] == 2) f3 = 1;
      if (!f3) {
        for (int i = 2; i <= n; ++i) printf("1 %d\n", i);
        return 0;
      }
      int u = 0, v = 0;
      for (int i = 1; i <= n; ++i) {
        int flg = 0;
        for (int j = 1; j <= n; ++j)
          if (num[i][j] == 2) {
            flg = 1;
            break;
          }
        if (!flg) {
          if (!u)
            u = i;
          else {
            v = i;
            break;
          }
        }
      }
      int p = 1;
      for (; p == u || p == v; ++p)
        ;
      printf("%d %d\n", u, v);
      printf("%d %d\n", p, u);
      for (int i = 1; i <= n; ++i)
        if (i != u && i != v && i != p) {
          if (num[i][p] == 2)
            printf("%d %d\n", v, i);
          else
            printf("%d %d\n", u, i);
        }
      return 0;
    }
    int rt = 1;
    for (;; ++rt) {
      int flg = 1;
      for (int i = 1; i <= n; ++i)
        if (i != rt && num[i][rt] < 3) {
          flg = 0;
          break;
        }
      if (flg) break;
    }
    vector<int> a, b;
    for (int i = 1; i <= n; ++i)
      if (i != rt) {
        int mi = 3;
        for (int j = 1; j <= n; ++j) mi = min(mi, num[i][j]);
        if (mi == 2)
          a.push_back(i);
        else
          b.push_back(i);
      }
    for (int i = 0; i < a.size(); ++i) printf("%d %d\n", a[i], rt);
    for (int i = 0; i < b.size(); ++i)
      for (int j = 0; j < a.size(); ++j)
        if (num[b[i]][a[j]] == 3) {
          printf("%d %d\n", b[i], a[j]);
          break;
        }
    return 0;
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (num[i][j] && num[i][j] < 3) {
        if (num[i][j] == 1)
          G[i].push_back(make_pair(j, 0)), G[j].push_back(make_pair(i, 0));
        else
          G[i].push_back(make_pair(j, 1)), G[j].push_back(make_pair(i, 1));
      }
  memset(col, -1, sizeof(col));
  int tot = 0;
  for (int i = 1; i <= n; ++i)
    if (!~col[i]) dfs(i, tot), tot += 2;
  int edgetot = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = i + 1; j <= n; ++j)
      if (num[i][j] == 3 && (col[i] >> 1) == (col[j] >> 1) && col[i] != col[j])
        printf("%d %d\n", i, j), edgetot++;
  return 0;
}