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 SIZE = 1100 / 64;
int N;
vector<int> S[1005];
int freq[1005];
unsigned long long A[1005][SIZE];
pair<int, int> intersect(int u, int v) {
  vector<int> res;
  for (int i = 0; i < SIZE; i++) {
    unsigned long long s = (A[u][i] & A[v][i]);
    if (s) {
      for (int b = 0; b < 64; b++) {
        if (s & (1LL << b)) {
          res.push_back(i * 64 + b);
          if (res.size() > 2) return make_pair(-1, -1);
        }
      }
    }
  }
  if (res.size() == 1) return make_pair(res[0], -1);
  if (res.size() != 2) return make_pair(-1, -1);
  return make_pair(res[0], res[1]);
}
bool E[1005][1005];
int deg[1005];
void add_edge(int u, int v) {
  E[u][v] = E[v][u] = true;
  deg[u]++;
  deg[v]++;
}
void print() {
  for (int i = 1; i <= N; i++)
    for (int j = i + 1; j <= N; j++)
      if (E[i][j]) cout << i << ' ' << j << endl;
  exit(0);
}
bool intl[1005];
vector<pair<int, int> > edge[1005];
bool dist2[1005][1005];
bool overshadows(int u, int v) {
  bool unequal = false;
  for (int i = 0; i < SIZE; i++) {
    if ((A[u][i] & A[v][i]) != A[v][i]) return false;
    if (A[u][i] != A[v][i]) unequal = true;
  }
  return unequal;
}
bool is_leaf(int i) {
  bool leaf = false;
  for (int j = 1; j <= N; j++) {
    if (j == i) continue;
    if (overshadows(i, j)) return false;
    if (overshadows(j, i)) leaf = true;
  }
  return leaf;
}
int main() {
  bool diam2 = true;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int k;
    cin >> k;
    if (k < N) diam2 = false;
    while (k--) {
      int x;
      cin >> x;
      S[i].push_back(x);
      freq[x]++;
      A[i][x / 64] ^= (1LL << (x % 64));
    }
  }
  if (diam2) {
    for (int i = 2; i <= N; i++) add_edge(1, i);
    print();
  }
  int num_center = 0;
  for (int i = 1; i <= N; i++)
    if (freq[i] == N) num_center++;
  if (num_center > 1) {
    int u = -1, v;
    for (int i = 1; i <= N; i++)
      if (freq[i] == N) {
        if (u == -1)
          u = i;
        else
          v = i;
      }
    if (0) printf("diam 3: u=%d v=%d\n", u, v);
    for (int i = 1; i <= N; i++) {
      if (S[i].size() == N) continue;
      for (int w = 1; w <= N; w++) {
        if (A[i][w / 64] & (1LL << (w % 64)))
          add_edge(w, u);
        else
          add_edge(w, v);
      }
      print();
    }
  }
  for (int i = 1; i <= N; i++)
    for (int j = i + 1; j <= N; j++) {
      pair<int, int> e = intersect(i, j);
      int u = e.first, v = e.second;
      if (v != -1) {
        if (0) printf("i=%d j=%d u=%d v=%d\n", i, j, u, v);
        add_edge(u, v);
        intl[u] = intl[v] = true;
        edge[i].push_back(e);
        edge[j].push_back(e);
      } else if (u != -1) {
        if (0) printf("dist2 i=%d u=%d\n", i, u);
        dist2[i][u] = dist2[j][u] = true;
      }
    }
  if (0)
    for (int i = 1; i <= N; i++)
      printf("is_leaf(%d) = %d\n", i, (int)is_leaf(i));
  for (int i = 1; i <= N; i++) {
    if (!is_leaf(i)) continue;
    int u, v, w;
    bool good = false;
    for (int j = 0; j < edge[i].size(); j++) {
      u = edge[i][j].first, v = edge[i][j].second;
      if (dist2[i][u]) {
        w = v;
        good = true;
        break;
      }
      if (dist2[i][v]) {
        w = u;
        good = true;
        break;
      }
    }
    if (good)
      ;
    else if (freq[u] == N)
      w = u;
    else if (freq[v] == N)
      w = v;
    else {
      printf("%d failed\n", i);
      return 0;
    }
    for (int j = 0; j < S[i].size(); j++) {
      int x = S[i][j];
      if (!intl[x]) add_edge(w, x);
    }
  }
  print();
}