#include <bits/stdc++.h>
int g[110][110];
int main() {
  int n, k;
  int m;
  while (scanf("%d %d", &n, &k) != EOF) {
    memset(g, 0, sizeof(g));
    int xc = (k + 1) / 2;
    int yc = (k + 1) / 2;
    for (int i = 0; i < n; ++i) {
      scanf("%d", &m);
      int minKey = 0x3f3f3f3f;
      int nowX = -1;
      int nowY = -1;
      for (int x = 1; x <= k; ++x) {
        for (int yr = m; yr <= k; ++yr) {
          int yl = yr + 1 - m;
          bool flag = true;
          int nowKey = 0;
          for (int j = yl; j <= yr; ++j) {
            if (g[x][j] != 0) {
              flag = false;
              break;
            }
            nowKey += (x < xc) ? (xc - x) : (x - xc);
            nowKey += (j < yc) ? (yc - j) : (j - yc);
          }
          if (flag && nowKey < minKey) {
            nowX = x;
            nowY = yr;
            minKey = nowKey;
          }
        }
      }
      if (nowX == -1) {
        printf("-1\n");
        continue;
      }
      int yl = nowY + 1 - m;
      for (int y = yl; y <= nowY; ++y) {
        g[nowX][y] = 1;
      }
      printf("%d %d %d\n", nowX, yl, nowY);
    }
  }
  return 0;
}
