#include <bits/stdc++.h>
using namespace std;
int cinema[101][101];
int com[101][101];
int main() {
  int n, k, c;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < k; i++)
    for (int j = 0; j < k; j++)
      com[i][j] = com[i][j - (j ? 1 : 0)] + abs((k / 2) - i) + abs((k / 2) - j);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c);
    int res = 1e9, ri, rj;
    for (int i = k - 1; i >= 0; i--) {
      int l = 0;
      for (int j = k - 1; j >= 0; j--) {
        if (cinema[i][j] == 1)
          l = 0;
        else
          l++;
        if (l >= c) {
          int t = com[i][j + c - 1] - (j ? com[i][j - 1] : 0);
          if (res >= t) {
            res = t;
            ri = i;
            rj = j;
          }
        }
      }
    }
    if (res == 1e9)
      cout << -1 << endl;
    else {
      cout << ri + 1 << " " << rj + 1 << " " << (rj + c) << endl;
      for (int i = rj; i < rj + c; i++) cinema[ri][i] = 1;
    }
  }
  return 0;
}
