#include <bits/stdc++.h>
using namespace std;
int m[1000], x[99][99];
int main() {
  bool aa = 0;
  long long n, k, mn, mn1 = 0, xx = 0, yl = 0, xc;
  cin >> n >> k;
  xc = k / 2;
  for (int i = 0; i < n; i++) cin >> m[i];
  for (int i = 0; i < n; i++) {
    mn = 9999999;
    yl = 999;
    for (int j = 0; j < k; j++) {
      for (int l = 0; l < k - m[i] + 1; l++) {
        aa = 1;
        mn1 = 0;
        for (int o = l; o < l + m[i]; o++) {
          if (x[j][o]) {
            aa = 0;
            l = o;
            break;
          }
          mn1 += abs(xc - j) + abs(xc - o);
        }
        if (aa && (mn1 < mn || (mn1 == mn && j < xx) ||
                   (mn1 == mn && j == xx && l < yl))) {
          mn = mn1;
          yl = l;
          xx = j;
        }
      }
    }
    if (mn == 9999999)
      cout << "-1\n";
    else {
      for (int j = yl; j < yl + m[i]; j++) x[xx][j] = 1;
      cout << xx + 1 << " " << yl + 1 << " " << yl + m[i] << '\n';
    }
  }
  return 0;
}
