#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e2 + 10;
int sum[N][N];
int flag[N][N];
int main() {
  int n, k;
  cin >> n >> k;
  int mid = (k + 1) / 2;
  while (n--) {
    int sz;
    cin >> sz;
    tuple<int, int, int> ans = {int(INF), -1, -1};
    for (int i = 1; i <= k; i++) {
      for (int j = sz; j <= k; j++) {
        if (sum[i][j] != sum[i][j - sz]) continue;
        int tot = abs(i - mid) * sz;
        for (int o = 0; o < sz; o++) {
          tot += abs(j - o - mid);
        }
        ans = min(ans, make_tuple(tot, i, j - sz + 1));
      }
    }
    int tot, x, y;
    tie(tot, x, y) = ans;
    if (tot == INF)
      puts("-1");
    else {
      printf("%d %d %d\n", x, y, y + sz - 1);
      for (int i = 0; i < sz; i++) flag[x][y + i] = 1;
      for (int i = 1; i <= k; i++) {
        sum[x][i] = sum[x][i - 1] + flag[x][i];
      }
    }
  }
  return 0;
}
