#include <bits/stdc++.h>
using namespace std;
bool hall[100][100];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    int m;
    scanf("%d", &m);
    int xc = k / 2;
    int yc = k / 2;
    int xo, yo, bo;
    bo = 1000000000;
    for (int x = 0; x < k; ++x)
      for (int y = 0; y + m <= k; ++y) {
        bool good = true;
        for (int i = 0; i < m; ++i)
          if (hall[x][y + i]) {
            good = false;
          }
        if (good) {
          int b = abs(x - xc) * m;
          for (int i = 0; i < m; ++i) b += abs(y + i - yc);
          if (b < bo || b == bo && (x < xo || x == xo && y < yo)) {
            bo = b;
            xo = x;
            yo = y;
          }
        }
      }
    if (bo == 1000000000) {
      printf("-1\n");
    } else {
      printf("%d %d %d\n", xo + 1, yo + 1, yo + m);
      for (int i = 0; i < m; ++i) hall[xo][yo + i] = true;
    }
  }
  return 0;
}
