#include <bits/stdc++.h>
using namespace std;
const double pi = 2.0 * acos(0.0);
const double eps = 1.0e-9;
const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};
const int dr6[] = {1, 1, 0, -1, -1, 0}, dc6[] = {0, 1, 1, 0, -1, -1};
const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1},
          dc8[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main(void) {
  int kase = 1000000000;
  for (int ks = 1, n, k; ks <= kase && 2 == scanf("%d %d", &n, &k); ++ks) {
    int cx = (k + 1) >> 1, cy = (k + 1) >> 1;
    vector<bitset<128> > seats(128);
    for (int i = 0, m; i < n && 1 == scanf("%d", &m); ++i) {
      int ux, uy, v = 1000000000;
      bitset<128> t;
      for (int j = 0; j < m; ++j) t.set(j);
      for (int x = 1; x <= k; ++x)
        for (int y = 1; y + m - 1 <= k; ++y)
          if (!((t << y) & seats[x]).any()) {
            int s = abs(x - cx) * m;
            for (int j = 0; j < m; ++j) s += abs(y + j - cy);
            if (s < v) ux = x, uy = y, v = s;
          }
      if (v < 1000000000)
        printf("%d %d %d\n", ux, uy, uy + m - 1), seats[ux] |= t << uy;
      else
        puts("-1");
    }
  }
  return 0;
}
