Problem: Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of presents in one box are distinct.

Having packed all the presents, Santa realized that different boxes can contain different number of presents. It would be unfair to the children, so he decided to move some presents between boxes, and make their sizes similar. After all movements, the difference between the maximal and the minimal number of presents in a box must be as small as possible. All presents in each box should still be distinct. Santa wants to finish the job as fast as possible, so he wants to minimize the number of movements required to complete the task.

Given the sets of presents in each box, find the shortest sequence of movements of presents between boxes that minimizes the difference of sizes of the smallest and the largest box, and keeps all presents in each box distinct.

Input

The first line of input contains two integers n, m (1 ≤ n, m ≤ 100\ 000), the number of boxes and the number of kinds of the presents. Denote presents with integers from 1 to m.

Each of the following n lines contains the description of one box. It begins with an integer s_i (s_i ≥ 0), the number of presents in the box, s_i distinct integers between 1 and m follow, denoting the kinds of presents in that box.

The total number of presents in all boxes does not exceed 500 000.

Output

Print one integer k at the first line of output, the number of movements in the shortest sequence that makes the sizes of the boxes differ by at most one. Then print k lines that describe movements in the same order in which they should be performed. Each movement is described by three integers from_i, to_i, kind_i. It means that the present of kind kind_i is moved from the box with number from_i to the box with number to_i. Boxes are numbered from one in the order they are given in the input.

At the moment when the movement is performed the present with kind kind_i must be present in the box with number from_i. After performing all moves each box must not contain two presents of the same kind.

If there are several optimal solutions, output any of them.

Example

Input


3 5
5 1 2 3 4 5
2 1 2
2 3 4


Output


2
1 3 5
1 2 3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline unsigned long long isqrt(unsigned long long k) {
  unsigned long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() { return abs((int)mt()); }
struct node_t {
  node_t *l, *r;
  int cnt;
  node_t(node_t* l = 0, node_t* r = 0, int cnt = 0) : l(l), r(r), cnt(cnt) {}
};
node_t* upd(node_t* p, int i, int L, int R, int val) {
  if (!p) p = new node_t();
  if (i < L || R < i) return p;
  if (L == R) {
    return new node_t(p->l, p->r, p->cnt + val);
  }
  node_t* res = new node_t(p->l, p->r);
  res->l = upd(res->l, i, L, L + R >> 1, val);
  res->r = upd(res->r, i, (L + R >> 1) + 1, R, val);
  res->cnt = res->l->cnt + res->r->cnt;
  return res;
}
int cnt(node_t* p) { return p ? p->cnt : 0; }
int query(node_t* p, node_t* q, int L, int R) {
  if (!p) p = new node_t();
  if (!q) q = new node_t();
  if (L == R) {
    return L;
  }
  if (cnt(p->l) > cnt(q->l)) {
    return query(p->l, q->l, L, L + R >> 1);
  } else {
    return query(p->r, q->r, (L + R >> 1) + 1, R);
  }
}
const int maxn = 1e5 + 5;
int n, m;
node_t* f[maxn];
void chemthan() {
  cin >> n >> m;
  vector<vector<int> > a(n);
  for (int i = (0); i < (n); ++i) {
    int k;
    cin >> k;
    a[i].resize(k);
    f[i] = new node_t();
    for (int& x : a[i]) {
      cin >> x, x--;
      f[i] = upd(f[i], x, 0, m - 1, 1);
    }
  }
  set<pair<int, int> > heap;
  for (int i = (0); i < (n); ++i) {
    heap.insert(make_pair(f[i]->cnt, i));
  }
  vector<pair<pair<int, int>, int> > res;
  while (1) {
    int u = heap.begin()->second;
    int v = heap.rbegin()->second;
    if (f[u]->cnt < f[v]->cnt - 1) {
      heap.erase(make_pair(f[u]->cnt, u));
      heap.erase(make_pair(f[v]->cnt, v));
      int x = query(f[v], f[u], 0, m - 1);
      f[v] = upd(f[v], x, 0, m - 1, -1);
      f[u] = upd(f[u], x, 0, m - 1, +1);
      heap.insert(make_pair(f[u]->cnt, u));
      heap.insert(make_pair(f[v]->cnt, v));
      res.push_back(make_pair(make_pair(v, u), x));
    } else {
      break;
    }
  }
  cout << int((res).size()) << "\n";
  for (auto e : res) {
    cout << e.first.first + 1 << " " << e.first.second + 1 << " "
         << e.second + 1 << "\n";
  }
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}