#include <bits/stdc++.h>
using namespace std;
struct BIT {
  int R[110];
  BIT() { memset(R, 0, sizeof(R)); }
  void push(int p, int how) {
    for (; p < 110; p += (p & (-p))) R[p] += how;
  }
  int vget(int p) {
    int ret = 0;
    for (; p > 0; p -= (p & (-p))) ret += R[p];
    return ret;
  }
  int iget(int f, int t) { return (vget(t) - vget(f - 1)); }
};
BIT used[110];
BIT dist[110];
int mx, my;
int N, K;
int main() {
  int i, j, k, l;
  scanf("%d%d", &N, &K);
  mx = my = ceil((K + 1.0) / 2);
  for (i = 1; i <= K; i++)
    for (j = 1; j <= K; j++) dist[i].push(j, abs(mx - i) + abs(my - j));
  for (int Q = 0; Q < N; Q++) {
    int H;
    scanf("%d", &H);
    int bst = 1000000000, bx = -1, by = -1;
    for (i = 1; i <= K; i++)
      for (j = 1; j <= (K + 1 - H); j++) {
        if (used[i].iget(j, j + H - 1) != 0) continue;
        int CS = dist[i].iget(j, j + H - 1);
        if (CS < bst) {
          bst = CS;
          bx = i;
          by = j;
        }
      }
    if (bx == -1)
      printf("-1\n");
    else {
      printf("%d %d %d\n", bx, by, by + H - 1);
      for (i = by; i <= by + H - 1; i++) used[bx].push(i, 1);
    }
  }
  return 0;
}
