#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, k, m;
  cin >> n >> k;
  const int MX = 100;
  int ar[MX][MX];
  int pref[MX][MX];
  int prefY[MX][MX];
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < k; ++j) {
      ar[i][j] = 1;
      pref[i][j] = j + 1;
      prefY[i][j] = abs((k + 1) / 2 - j - 1) + abs((k + 1) / 2 - i - 1);
      if (j != 0) prefY[i][j] += prefY[i][j - 1];
    }
  }
  for (int t = 0; t < n; ++t) {
    cin >> m;
    int mi = 1e9, a = -1, b = -1;
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j <= k - m; ++j) {
        int emp = pref[i][j + m - 1];
        if (j > 0) emp -= pref[i][j - 1];
        if (emp == m) {
          int ts = prefY[i][j + m - 1];
          if (j > 0) ts -= prefY[i][j - 1];
          if (ts < mi) {
            mi = ts;
            a = i;
            b = j;
          }
        }
      }
    }
    if (a == -1 || b == -1)
      cout << -1 << endl;
    else {
      cout << a + 1 << " " << b + 1 << " " << b + m << endl;
      for (int i = b; i <= b + m - 1; ++i) ar[a][i] = 0;
      for (int i = b; i <= b + m - 1; ++i) pref[a][i] -= i + 1 - b;
      for (int i = b + m; i < k; ++i) pref[a][i] -= m;
    }
  }
  return 0;
}
