#include <bits/stdc++.h>
using namespace std;
bool check[1002][1002];
int main() {
  int n, k, m;
  scanf("%d %d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &m);
    int xm = 0, yl = 0, yr = 0, chk = 1e9, yc = (k + 1) / 2, xc = (k + 1) / 2;
    for (int x = 1; x <= k; ++x) {
      for (int ylmin = 1; ylmin <= k - m + 1; ++ylmin) {
        int sum = 0;
        bool ok = 1;
        for (int y = ylmin; y <= ylmin + m - 1; ++y) {
          if (check[x][y]) {
            ok = 0;
            break;
          }
          sum += abs(x - xc) + abs(y - yc);
        }
        if (ok && sum < chk) chk = sum, xm = x, yl = ylmin, yr = ylmin + m - 1;
      }
    }
    if (chk == 1e9) {
      puts("-1");
      continue;
    }
    for (int y = yl; y <= yr; ++y) check[xm][y] = 1;
    printf("%d %d %d\n", xm, yl, yr);
  }
}
