#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main(void) {
  int n, k, xc, yc, m, st, mmin, row, sum, dist;
  scanf("%d%d", &n, &k);
  xc = ceil(k / 2.0);
  yc = ceil(k / 2.0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    mmin = 10000;
    st = -1;
    row = -1;
    for (int j = 1; j <= k; j++) {
      sum = 0;
      dist = 0;
      for (int p = 1; p <= m; p++) {
        sum += a[j][p];
        dist += abs(xc - j) + abs(yc - p);
      }
      if (sum == 0) {
        if (dist < mmin) {
          mmin = dist;
          st = 1;
          row = j;
        }
      }
      for (int p = m + 1; p <= k; p++) {
        sum -= a[j][p - m];
        sum += a[j][p];
        dist -= abs(yc - (p - m));
        dist += abs(yc - p);
        if (sum == 0)
          if (dist < mmin) {
            mmin = dist;
            st = p - m + 1;
            row = j;
          }
      }
    }
    if (mmin == 10000)
      printf("-1\n");
    else {
      printf("%d %d %d\n", row, st, st + m - 1);
      for (int j = 0; j < m; j++) a[row][j + st] = 1;
    }
  }
  return 0;
}
