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>
inline int lowbit(unsigned long long x) {
  int y = 0;
  if (!(x & 4294967295)) x >>= 32, y += 32;
  if (!(x & 65535)) x >>= 16, y += 16;
  if (!(x & 255)) x >>= 8, y += 8;
  if (!(x & 15)) x >>= 4, y += 4;
  if (!(x & 3)) x >>= 2, y += 2;
  if (!(x & 1)) y++;
  return y;
}
int e[1001], f[1001], h[65536], u, v, z;
unsigned long long c[1001][16], d[1001][16], g[16], w;
inline int count(unsigned long long x) {
  return h[x & 65535] + h[x >> 16 & 65535] + h[x >> 32 & 65535] +
         h[x >> 48 & 65535];
}
int find(int x) { return f[x] ? f[x] = find(f[x]) : x; }
inline void find(unsigned long long* a, unsigned long long* b) {
  int x = 0, y;
  for (int j = 0; j < 16; j++) x += count(a[j] & b[j]);
  if (x == 2)
    for (int j = 0; j < 16; j++)
      if (w = a[j] & b[j])
        while (w) y = lowbit(w), u = v, v = y | j << 6, w ^= 1llu << y;
  if (x == 2 && find(u) != find(v))
    printf("%d %d\n", u, v),
        f[find(u)] = find(v), d[u][v >> 6] |= 1llu << (v & 63),
        g[v >> 6] |= 1llu << (v & 63), d[v][u >> 6] |= 1llu << (u & 63),
        g[u >> 6] |= 1llu << (u & 63), z++;
}
inline bool equal(unsigned long long* a, unsigned long long* b) {
  for (int j = 0; j < 16; j++)
    if (a[j] != (b[j] & g[j])) return false;
  return true;
}
int i, j, n;
int main() {
  scanf("%d", &n);
  if (n == 2) return 0 * puts("1 2");
  for (i = 1; i < 65536; i++) h[i] = h[i >> 1] + (i & 1);
  for (i = 1; i <= n; d[i][i >> 6] |= 1llu << (i & 63), i++)
    for (scanf("%d", e + i), j = 0; j < e[i]; j++)
      scanf("%d", &v), c[i][v >> 6] |= 1llu << (v & 63);
  for (i = 1; i < n; i++)
    for (j = i + 1; j <= n; j++) find(c[i], c[j]);
  if (!z)
    for (i = 2; i <= n; i++) printf("1 %d\n", i);
  else if (z == 1) {
    for (i = 1; i <= n; i++)
      if (c[i][u >> 6] >> (u & 63) & 1) {
        for (j = 1; j <= n; j++)
          if (~c[i][j >> 6] >> (j & 63) & 1) break;
        if (j <= n) break;
      }
    for (j = 1; j <= n; j++)
      if (j != u && j != v)
        printf("%d %d\n", ~c[i][j >> 6] >> (j & 63) & 1 ? u : v, j);
  } else
    for (i = 1; i <= n; i++)
      if (~g[i >> 6] >> (i & 63) & 1) {
        for (j = 1, u = 0; j <= n; j++)
          if ((c[j][i >> 6] >> (i & 63) & 1) && (!u || e[j] < e[u])) u = j;
        for (j = 1; j <= n; j++)
          if (equal(d[j], c[u])) printf("%d %d\n", i, j);
      }
  return 0;
}