#include <bits/stdc++.h>
using namespace std;
const int mk = 101;
int q, k;
int su[mk][mk], sv[mk][mk];
int xc, yc;
int main() {
  q = ({
    int t;
    scanf("%d", &t);
    t;
  }),
  k = ({
    int t;
    scanf("%d", &t);
    t;
  });
  xc = (k + 1) / 2, yc = (k + 1) / 2;
  for (int i = 1; i < k + 1; i++)
    for (int j = 1; j < k + 1; j++)
      su[i][j] = j, sv[i][j] = sv[i][j - 1] + abs(i - xc) + abs(j - yc);
  for (int qu = 0; qu < q; qu++) {
    int m = ({
      int t;
      scanf("%d", &t);
      t;
    });
    int ansv = (int)1e9, ansx = -1, ansyl = -1, ansyr = -1;
    for (int x = 1; x < k + 1; x++)
      for (int yl = 1; yl < k + 1; yl++) {
        int yr = yl + m - 1;
        if (yr > k) break;
        if (su[x][yr] - su[x][yl - 1] != m) continue;
        int v = sv[x][yr] - sv[x][yl - 1];
        if (v < ansv) {
          ansv = v, ansx = x, ansyl = yl, ansyr = yr;
        }
      }
    if (ansx == -1) {
      printf("-1\n");
      continue;
    }
    printf("%d %d %d\n", ansx, ansyl, ansyr);
    int x = ansx;
    for (int j = ansyl; j < ansyr + 1; j++)
      su[x][j] = su[x][j - 1], sv[x][j] = sv[x][j - 1];
    for (int j = ansyr + 1; j < k + 1; j++)
      su[x][j] -= m, sv[x][j] = sv[x][j - 1] + abs(x - xc) + abs(j - yc);
  }
  return 0;
}
