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;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug &operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug &operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
const long double eps = 1e-9;
const long long inf = 1e18;
auto rnd = bind(uniform_int_distribution<int>(0, 63), mt19937(time(0)));
auto rndd = bind(uniform_int_distribution<int>(55, 55), mt19937(time(0)));
const int N = 1e5 + 1;
set<long long> have_lower[N];
set<long long> have_greater[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long n, m;
  cin >> n >> m;
  long long l, r;
  vector<long long> second(n);
  vector<vector<long long>> a(n, vector<long long>());
  long long sm = 0;
  for (long long i = 0; i < n; i++) {
    cin >> second[i];
    a[i].resize(second[i]);
    for (long long j = 0; j < second[i]; j++) {
      cin >> a[i][j];
      --a[i][j];
    }
    sm += second[i];
  }
  l = sm / n, r = ceil((long double)sm / n);
  long long cll = n - (sm % n);
  long long clr = sm % n;
  set<long long> blya_upd;
  for (long long i = 0; i < n; i++) {
    if (second[i] == l) {
      if (cll != 0) {
        cll--;
        continue;
      }
    }
    if (second[i] == r) {
      if (clr != 0) {
        clr--;
        continue;
      }
    }
    if (second[i] >= r) {
      for (auto &z : a[i]) have_greater[z].insert(i);
    } else {
      for (auto &z : a[i]) {
        have_lower[z].insert(i);
      }
      blya_upd.insert(i);
    }
  }
  vector<pair<long long, pair<long long, long long>>> ans;
  set<long long> pob;
  for (long long i = 0; i < m; i++) {
    pob.clear();
    for (auto &z : have_lower[i]) {
      blya_upd.erase(z);
    }
    while ((long long)blya_upd.size() && (long long)have_greater[i].size()) {
      long long from = *have_greater[i].rbegin();
      long long to = *blya_upd.begin();
      second[from]--;
      second[to]++;
      if (second[to] == l && cll) {
        for (auto &z : a[to]) {
          have_lower[z].erase(to);
        }
        cll--;
      } else if (second[to] == r) {
        assert(clr);
        clr--;
        for (auto &z : a[to]) {
          have_lower[z].erase(to);
        }
      } else {
        pob.insert(to);
      }
      if (second[from] == r && clr) {
        for (auto &z : a[from]) {
          have_greater[z].erase(from);
        }
        clr--;
      } else if (second[from] == l) {
        assert(cll);
        cll--;
        for (auto &z : a[from]) {
          have_greater[z].erase(from);
        }
      }
      ans.push_back({i, {from, to}});
      have_greater[i].erase(from);
      blya_upd.erase(to);
    }
    for (auto &z : pob) blya_upd.insert(z);
    for (auto &z : have_lower[i]) {
      blya_upd.insert(z);
    }
  }
  cout << (long long)ans.size() << '\n';
  for (auto &z : ans) {
    cout << z.second.first + 1 << ' ' << z.second.second + 1 << ' '
         << z.first + 1 << '\n';
  }
  return 0;
}