#include <bits/stdc++.h>
using namespace std;
int ydist[100][100];
int matr[100][100];
int n, k;
int c;
void build_ydist() {
  for (int l = 0; l < k; l++) {
    for (int r = l; r < k; r++) {
      ydist[l][r] = 0;
      for (int i = l; i <= r; i++) ydist[l][r] += abs((double)c - i);
    }
  }
}
int main() {
  cin >> n >> k;
  c = round((double)((double)(k - 1)) / 2);
  build_ydist();
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++) matr[i][j] = 0;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    int res = 9999999;
    int nres;
    int resx = -1, resyl = -1, resyr = -1;
    for (int x = 0; x < k; x++) {
      int alr = 0;
      for (int y = 0; y < k; y++) {
        if (matr[x][y] == 0)
          alr++;
        else
          alr = 0;
        if (alr >= m) {
          nres = ydist[y - m + 1][y] + m * abs((double)x - c);
          if (nres < res) {
            res = nres;
            resx = x;
            resyl = y - m + 1;
            resyr = y;
          }
        }
      }
    }
    if (resx == -1) {
      cout << "-1\n";
      continue;
    }
    for (int y = resyl; y <= resyr; y++) matr[resx][y] = 1;
    cout << resx + 1 << " " << resyl + 1 << " " << resyr + 1 << "\n";
  }
  return 0;
}
