#include <bits/stdc++.h>
using namespace std;
int s[111][111], g[111][111];
int i, j, k, n, m;
void solve(int m) {
  int x, y, tmp, ans = INT_MAX;
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= k; ++j) {
      if (!g[i][j]) {
        if (j >= m && s[i][j] - s[i][j - m] < ans) {
          ans = s[i][j] - s[i][j - m];
          x = i, y = j - m + 1;
        }
      } else
        break;
    }
    for (j = k - 1; j >= 0; --j) {
      if (!g[i][j + 1]) {
        if (j + m <= k && s[i][j + m] - s[i][j] < ans) {
          ans = s[i][j + m] - s[i][j];
          x = i, y = j + 1;
        }
      } else
        break;
    }
  }
  if (ans < INT_MAX) {
    cout << x << " " << y << " " << y + m - 1 << "\n";
    while (m--) g[x][y++] = 1;
  } else
    puts("-1");
}
int main() {
  cin >> n >> k;
  memset(s, 0, sizeof(s));
  memset(g, 0, sizeof(g));
  for (i = 1; i <= k; ++i) {
    for (j = 1; j <= k; ++j) {
      s[i][j] = abs(i - (k + 1) / 2) + abs(j - (k + 1) / 2);
      s[i][j] += s[i][j - 1];
    }
  }
  while (n--) {
    cin >> m;
    solve(m);
  }
  return 0;
}
