#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int b[100][100];
int sum[100][100];
int sum2[100][100];
int n, k, i, j, m;
int yc, xc;
int main() {
  cin >> n >> k;
  for (i = 0; i <= k; i++)
    for (j = 0; j <= k; j++) {
      a[i][j] = 0;
      b[i][j] = 0;
      sum[i][j] = 0;
      sum2[i][j] = 0;
    }
  yc = k / 2 + 1;
  xc = k / 2 + 1;
  for (i = 1; i <= k; i++)
    for (j = 1; j <= k; j++) {
      b[i][j] = abs(i - yc) + abs(j - xc);
      sum[i][j] = sum[i][j - 1] + b[i][j];
      sum2[i][j] = 0;
    }
  for (int z = 1; z <= n; z++) {
    cin >> m;
    int minimal = 1000000000;
    int l = 0;
    int r = 0;
    int ryad = 0;
    for (i = 1; i <= k; i++)
      for (j = 1; j <= k; j++)
        if ((j + m - 1 <= k) &&
            (sum2[i][j + m - 1] - sum2[i][j] + a[i][j]) == 0 &&
            (sum[i][j + m - 1] - sum[i][j] + b[i][j]) < minimal) {
          minimal = (sum[i][j + m - 1] - sum[i][j] + b[i][j]);
          l = j;
          r = j + m - 1;
          ryad = i;
        }
    if (minimal != 1000000000) {
      cout << ryad << " " << l << " " << r << endl;
      for (i = l; i <= r; i++) a[ryad][i] = 1;
    } else
      cout << "-1" << endl;
    for (i = 1; i <= k; i++)
      for (j = 1; j <= k; j++) {
        sum2[i][j] = sum2[i][j - 1] + a[i][j];
      }
  }
  return 0;
}
