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;
long long modx(long long Base, long long exponent) {
  long long ans = 1;
  if (Base == 1) return Base;
  while (exponent) {
    if (exponent & 1) ans = (ans * Base) % 1000000007LL;
    Base = (Base * Base) % 1000000007LL;
    exponent = exponent >> 1;
  }
  return ans;
}
long long inmodx(long long num) { return (modx(num, 1000000007LL - 2LL)); }
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second < b.second) return 1;
  if (a.second > b.second) return 0;
  if (a.first <= b.first) return 1;
  return 0;
}
const int N = (1e5) + 9;
const int M = (N << 2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 450;
set<int> a[N];
pair<int, int> st[M];
vector<pair<pair<int, int>, int> > ans;
vector<int> brr, arr[N], crr;
void update_ans(int from, int to, int val) {
  ans.push_back(make_pair(make_pair(from, to), val));
  return;
}
void build(int node, int l, int r) {
  if (l > r) return;
  if (l == r) {
    st[node] = {(int)((a[l]).size()), l};
    return;
  }
  int mid = (l + r) >> 1;
  int left = node << 1;
  int right = left | 1;
  build(left, l, mid);
  build(right, mid + 1, r);
  st[node] = min(st[left], st[right]);
  return;
}
void update(int node, int l, int r, int ind, pair<int, int> val) {
  if (l > r || ind < l || ind > r) return;
  if (l == r) {
    st[node] = val;
    return;
  }
  int mid = (l + r) >> 1;
  int left = node << 1;
  int right = left | 1;
  update(left, l, mid, ind, val);
  update(right, mid + 1, r, ind, val);
  st[node] = min(st[left], st[right]);
  return;
}
void solve() {
  int n, m, i, j, d, x, sum = 0;
  pair<int, int> X, val;
  cin >> n >> m;
  sum = 0;
  for (i = (1); i < (n + 1); i++) {
    cin >> d;
    sum += d;
    while (d--) {
      cin >> x;
      a[i].insert(x);
    }
  }
  X = {sum / n, (sum + n - 1) / n};
  for (i = (1); i < (n + 1); i++)
    for (auto x : a[i]) arr[x].push_back(i);
  build(1, 1, n);
  for (i = (1); i < (m + 1); i++) {
    brr.clear();
    for (auto x : arr[i]) update(1, 1, n, x, make_pair(1000000011, x));
    for (auto x : arr[i]) {
      if ((int)((a[x]).size()) <= X.second) continue;
      val = st[1];
      if (val.first >= X.first) break;
      a[val.second].insert(i);
      update(1, 1, n, val.second, make_pair(1000000011, val.second));
      brr.push_back(val.second);
      a[x].erase(i);
      update_ans(x, val.second, i);
    }
    for (auto x : arr[i])
      update(1, 1, n, x, make_pair((int)((a[x]).size()), x));
    for (auto x : brr) update(1, 1, n, x, make_pair((int)((a[x]).size()), x));
  }
  int fuck = 0;
  d = 0;
  for (i = (1); i < (n + 1); i++)
    if ((int)((a[i]).size()) < X.first) {
      fuck++;
      d = 1;
      break;
    }
  if (d == 1) {
    for (i = (1); i < (m + 1); i++) arr[i].clear();
    for (i = (1); i < (n + 1); i++)
      for (auto x : a[i]) arr[x].push_back(i);
    for (i = (1); i < (m + 1); i++) {
      brr.clear();
      for (auto x : arr[i]) update(1, 1, n, x, make_pair(1000000011, x));
      for (auto x : arr[i]) {
        if ((int)((a[x]).size()) < X.second) continue;
        val = st[1];
        if (val.first >= X.first) break;
        a[val.second].insert(i);
        update(1, 1, n, val.second, make_pair(1000000011, val.second));
        brr.push_back(val.second);
        a[x].erase(i);
        update_ans(x, val.second, i);
      }
      for (auto x : arr[i])
        update(1, 1, n, x, make_pair((int)((a[x]).size()), x));
      for (auto x : brr) update(1, 1, n, x, make_pair((int)((a[x]).size()), x));
    }
  }
  d = 0;
  for (i = (1); i < (n + 1); i++)
    if ((int)((a[i]).size()) > X.second) {
      fuck++;
      d = 1;
      break;
    }
  if (d == 1) {
    for (i = (1); i < (m + 1); i++) arr[i].clear();
    for (i = (1); i < (n + 1); i++)
      for (auto x : a[i]) arr[x].push_back(i);
    for (i = (1); i < (m + 1); i++) {
      brr.clear();
      for (auto x : arr[i]) update(1, 1, n, x, make_pair(1000000011, x));
      for (auto x : arr[i]) {
        if ((int)((a[x]).size()) <= X.second) continue;
        val = st[1];
        if (val.first > X.first) break;
        a[val.second].insert(i);
        update(1, 1, n, val.second, make_pair(1000000011, val.second));
        brr.push_back(val.second);
        a[x].erase(i);
        update_ans(x, val.second, i);
      }
      for (auto x : arr[i])
        update(1, 1, n, x, make_pair((int)((a[x]).size()), x));
      for (auto x : brr) update(1, 1, n, x, make_pair((int)((a[x]).size()), x));
    }
  }
  assert(fuck < 2);
  cout << (int)((ans).size()) << '\n';
  for (auto x : ans)
    cout << x.first.first << " " << x.first.second << " " << x.second << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  clock_t clk;
  clk = clock();
  int t = 1, cs;
  cout << fixed << setprecision(3);
  for (cs = (1); cs < (t + 1); cs++) {
    solve();
  }
  clk = clock() - clk;
  cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
       << "\n";
  return 0;
}