#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[101][101] = {};
  int n, k;
  cin >> n >> k;
  int o = (k + 1) / 2;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    int c = 1 << 30;
    int cx, cy;
    for (int x = 1; x <= k; x++) {
      int r = 0;
      int d = 0;
      for (int y = 1; y <= k; y++) {
        if (s[x][y]) {
          r = 0;
          d = 0;
        } else {
          r++;
          d += abs(x - o);
          d += abs(y - o);
          if (r > m) {
            d -= abs(x - o);
            d -= abs(y - m - o);
          }
          if (r >= m && d < c) {
            c = d;
            cx = x;
            cy = y - m + 1;
          }
        }
      }
    }
    if (c < (1 << 30)) {
      cout << cx << " " << cy << " " << cy + m - 1 << endl;
      for (int y = cy; y < cy + m; y++) {
        s[cx][y] = 1;
      }
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
