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 int mod = 1e9 + 7;
double eps = 1e-7;
long long int exp(long long int x, long long int y) {
  if (y < 0) return 0;
  long long int ret = 1;
  for (; y; y >>= 1, x = (x * x) % mod) {
    if (y & 1) ret = (ret * x) % mod;
  }
  return ret;
}
unsigned long long int pexp(unsigned long long int x,
                            unsigned long long int y) {
  if (y < 0) return 0;
  unsigned long long int ret = 1;
  for (; y; y >>= 1, x = (x * x)) {
    if (y & 1) ret = (ret * x);
  }
  return ret;
}
long long int gcd(long long int x, long long int y) {
  if (!x || !y) return x + y;
  return x % y == 0 ? y : gcd(y, x % y);
}
long long int lcm(long long int x, long long int y) {
  return x * (y / gcd(x, y));
}
long long int bsum(long long int u, long long int b) {
  long long int ret = 0;
  if (u < b) return u;
  while (u) {
    ret += u % b;
    u /= b;
  }
  return ret;
}
long long int prival(long long int u, long long int p) {
  long long int cn = 0;
  while (u % p == 0) {
    cn++;
    u = u / p;
  }
  return cn;
}
long long int minv(long long int a, long long int b) {
  return 1 < a ? b - minv(b % a, a) * b / a : 1;
}
long long int extm(long long int a, long long int b) {
  long long int ret = 0;
  while (a != 0) {
    if (a % 2 == 1) {
      ret += b;
      ret %= mod;
    }
    a >>= 1;
    b = (2 * b) % mod;
  }
  return ret;
}
long long int eaphi(long long int x) {
  long long int t = x, ret = x, i;
  for (i = 2; i * i <= x; i++) {
    if (t % i == 0) {
      ret -= ret / i;
      while (t % i == 0) t /= i;
    }
  }
  if (t != 1) ret -= ret / t;
  return ret;
}
long long int eadivc(long long int x) {
  long long int ret = 0;
  long long int i;
  for (i = 1; i * i <= x; i++) {
    if (x % i == 0 && i * i != x) ret += 2;
    if (x % i == 0 && i * i == x) ret += 1;
  }
  return ret;
}
long long int eadivs(long long int x) {
  long long int ret = 0;
  long long int i;
  for (i = 1; i * i <= x; i++) {
    if (x % i == 0 && i * i != x) ret += i + x / i;
    if (x % i == 0 && i * i == x) ret += i;
  }
  return ret;
}
long long int ndig(long long int x, long long int b) {
  long long int ret = 0;
  while (x) {
    x /= b;
    ret++;
  }
  return ret;
}
long long int rev(long long int n, long long int b) {
  long long int ret = 0;
  while (n) {
    ret = b * ret + n % b;
    n /= b;
  }
  return ret;
}
long long int sq(long long int x) {
  long long int t = (long long int)sqrt(x);
  for (long long int i = t - 2; i <= t + 2; i++)
    if (i * i == x) return abs(i);
  return -1;
}
long long int extexp(long long int x, long long int y) {
  if (y < 0) return 0;
  long long int ret = 1;
  for (; y; y >>= 1, x = extm(x, x)) {
    if (y & 1) ret = extm(ret, x);
  }
  return ret;
}
bool isprime(long long int x) {
  if (x <= 1) return false;
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
int n, m, tot, pivot_1, pivot_2, goal[111111];
struct BOX {
  set<int> world;
  int index;
} stf[111111];
vector<pair<int, pair<int, int> > > FIN;
set<int>::iterator it;
bool cmp(const BOX &A, const BOX &B) { return A.world.size() > B.world.size(); }
void work(int u, int v) {
  vector<int> SX;
  SX.clear();
  int i;
  int sz_cut =
      min(stf[u].world.size() - goal[u], goal[v] - stf[v].world.size());
  for (it = stf[u].world.begin(); it != stf[u].world.end(); it++) {
    if (stf[v].world.find((*it)) == stf[v].world.end()) SX.push_back((*it));
    if (SX.size() >= sz_cut) break;
  }
  for (i = 0; i < SX.size(); i++) {
    FIN.push_back(make_pair(stf[u].index, make_pair(stf[v].index, SX[i])));
    stf[u].world.erase(SX[i]);
    stf[v].world.insert(SX[i]);
  }
}
int main(void) {
  int i, j, x, xx;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> x;
    tot += x;
    for (j = 1; j <= x; j++) {
      cin >> xx;
      stf[i].world.insert(xx);
    }
    stf[i].index = i;
  }
  sort(stf + 1, stf + n + 1, cmp);
  for (i = 1; i <= tot % n; i++) goal[i] = tot / n + 1;
  for (i = tot % n + 1; i <= n; i++) goal[i] = tot / n;
  pivot_2 = n + 1;
  for (i = 1; i <= n; i++) {
    if (stf[i].world.size() < goal[i]) pivot_2 = i;
    if (stf[i].world.size() < goal[i]) break;
  }
  pivot_1 = 1;
  while (pivot_2 <= n) {
    while (stf[pivot_1].world.size() != goal[pivot_1] &&
           stf[pivot_2].world.size() != goal[pivot_2])
      work(pivot_1, pivot_2);
    if (stf[pivot_1].world.size() == goal[pivot_1]) pivot_1++;
    if (stf[pivot_2].world.size() == goal[pivot_2]) pivot_2++;
    if (pivot_2 > n) break;
  }
  cout << FIN.size() << endl;
  for (i = 0; i < FIN.size(); i++)
    cout << FIN[i].first << " " << FIN[i].second.first << " "
         << FIN[i].second.second << "\n";
  return 0;
}