#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:20000000")
string problem_name = "a";
void init() { freopen((problem_name + ".in").c_str(), "rt", stdin); }
int mas[111][111];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int xc = k / 2 + 1, yc = k / 2 + 1;
  while (n--) {
    int m;
    scanf("%d", &m);
    int res = 1 << 30;
    int xr, yr;
    for (int i = 1; i <= k; i++) {
      int cur = 0, sum = 0;
      for (int j = 1; j <= m; j++) {
        sum += mas[i][j];
        cur += abs(i - xc) + abs(j - yc);
      }
      for (int j = 1; j + m - 1 <= k; j++) {
        if (sum == 0) {
          if (cur < res) {
            res = cur;
            xr = i;
            yr = j;
          }
        }
        sum -= mas[i][j];
        sum += mas[i][j + m];
        cur -= abs(yc - j);
        cur += abs(yc - (j + m));
      }
    }
    if (res < 1 << 30) {
      for (int j = 1; j <= m; j++) mas[xr][yr + j - 1] = 1;
      printf("%d %d %d\n", xr, yr, yr + m - 1);
    } else
      printf("-1\n");
  }
  return 0;
}
