#include <bits/stdc++.h>
using namespace std;
const long long A = 100000000000000LL, N = 228;
long long i, j, n, m, _x, _y, o[3], d, dp[2][N][N], Set[N][N];
void buildDP() {
  for (i = 0; i < m; i++) {
    dp[1][i][0] = Set[i][0];
    for (j = 1; j < m; j++) dp[1][i][j] = dp[1][i][j - 1] + Set[i][j];
  }
}
long long get(int type, int x, int l, int r) {
  if (!l)
    return dp[type][x][r];
  else
    return dp[type][x][r] - dp[type][x][l - 1];
}
int main() {
  cin >> n >> m;
  _x = _y = (m + 1) / 2;
  for (i = 1; i <= m; i++)
    for (j = 1; j <= m; j++) dp[0][i - 1][j - 1] = abs(_x - i) + abs(_y - j);
  for (i = 0; i < m; i++)
    for (j = 1; j < m; j++) dp[0][i][j] += dp[0][i][j - 1];
  while (n--) {
    buildDP();
    scanf("%d", &d), o[0] = A, o[1] = -1, o[2] = -1;
    for (i = 0; i < m; i++)
      for (j = 0; j < m && j + d - 1 < m; j++)
        if (!get(1, i, j, j + d - 1) && get(0, i, j, j + d - 1) < o[0])
          o[0] = get(0, i, j, j + d - 1), o[1] = i, o[2] = j;
    if (o[1] == -1) {
      puts("-1");
      continue;
    }
    for (j = o[2]; j < o[2] + d; j++) Set[o[1]][j] = 1;
    cout << o[1] + 1 << " " << o[2] + 1 << " " << o[2] + d << "\n";
  }
}
