#include <bits/stdc++.h>
using namespace std;
const int K = 1111;
int cine[K][K], n, k;
int main() {
  scanf("%d%d", &n, &k);
  int mid = k / 2;
  while (n--) {
    int m;
    scanf("%d", &m);
    int minS = 1 << 30, x, l, r;
    for (int i = 0; i < k; ++i) {
      int s = 0, cnt = 0;
      for (int j = 0; j < k; ++j)
        if (cine[i][j] == 0) {
          s += abs(i - mid) + abs(j - mid);
          if (++cnt > m) --cnt, s -= abs(i - mid) + abs(j - m - mid);
          if (cnt == m && s < minS) minS = s, x = i, r = j, l = r - m + 1;
        } else
          s = 0, cnt = 0;
    }
    if (minS == (1 << 30))
      printf("-1\n");
    else {
      printf("%d %d %d\n", x + 1, l + 1, r + 1);
      for (int i = l; i <= r; ++i) cine[x][i] = 1;
    }
  }
  return 0;
}
