#include <bits/stdc++.h>
using namespace std;
int n, k;
int s[100][100];
bool f[100][100];
void solve() {
  int i, j, l, k2;
  int m, t, r, c;
  k2 = (k + 1) / 2;
  memset(f, false, sizeof(f));
  for (i = 1; i <= k; ++i) {
    s[i][0] = 0;
    for (j = 1; j <= k; ++j) s[i][j] = abs(i - k2) + abs(j - k2) + s[i][j - 1];
  }
  while (n--) {
    scanf("%d", &m);
    t = 100000000;
    r = c = -1;
    for (i = 1; i <= k; ++i) {
      for (j = 1; j <= k - m + 1; ++j) {
        for (l = 0; l < m; ++l) {
          if (!f[i][j + l]) continue;
          j = j + l;
          break;
        }
        if (l >= m && t > s[i][j + m - 1] - s[i][j - 1])
          t = s[i][j + m - 1] - s[i][j - 1], r = i, c = j;
      }
    }
    if (-1 == r)
      printf("-1\n");
    else {
      printf("%d %d %d\n", r, c, c + m - 1);
      for (i = c; i < c + m; ++i) f[r][i] = true;
    }
  }
}
int main() {
  while (scanf("%d %d", &n, &k) != EOF) solve();
  return 0;
}
