#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > S[105];
int N, K, mid;
set<pair<int, int> >::iterator it;
int i, j, k, m;
int cx, cyl, cyr, cd, cy1, cy2;
int bx, byl, byr, bd, by1, by2;
void update() {
  if (cd > bd) return;
  if (cd < bd) {
    bd = cd;
    bx = cx;
    byl = cyl;
    byr = cyr;
    by1 = cy1;
    by2 = cy2;
  } else if (cd == cd) {
    if (cx < bx || (cx == bx && cyl < byl)) {
      bd = cd;
      bx = cx;
      byl = cyl;
      byr = cyr;
      by1 = cy1;
      by2 = cy2;
    }
  }
}
int main() {
  cin >> N >> K;
  mid = (K + 1) / 2;
  for (i = 1; i <= K; i++) S[i].insert(make_pair(1, K));
  while (N--) {
    cin >> m;
    bd = 100000000;
    for (i = 1; i <= K; i++) {
      cx = i;
      for (it = S[i].begin(); it != S[i].end(); it++) {
        cy1 = (*it).first, cy2 = (*it).second;
        if (cy2 - cy1 + 1 < m) continue;
        if (cy1 > mid) {
          cd = m * abs(i - mid) + m * (cy1 - mid) + m * (m - 1) / 2;
          cyl = cy1;
          cyr = cy1 + m - 1;
          update();
        } else if (cy2 < mid) {
          cd = m * abs(i - mid) + m * (mid - cy2) + m * (m - 1) / 2;
          cyr = cy2;
          cyl = cy2 - m + 1;
          update();
        } else if (cy1 <= mid && cy2 >= mid) {
          cyl = mid - (m / 2);
          cyr = mid + (m - 1) / 2;
          if (cyr > cy2) {
            cyr = cy2;
            cyl = cy2 - m + 1;
          } else if (cyl < cy1) {
            cyl = cy1;
            cyr = cy1 + m - 1;
          }
          cd = m * abs(i - mid);
          k = mid - cyl;
          cd += k * (k + 1) / 2;
          k = cyr - mid;
          cd += k * (k + 1) / 2;
          update();
        }
      }
    }
    if (bd == 100000000)
      cout << -1 << endl;
    else
      cout << bx << " " << byl << " " << byr << endl;
    if (bd != 100000000) {
      S[bx].erase(make_pair(by1, by2));
      S[bx].insert(make_pair(by1, byl - 1));
      S[bx].insert(make_pair(byr + 1, by2));
    }
  }
  return 0;
}
