#include <bits/stdc++.h>
using namespace std;
int xc, yc, k;
int a[1001][1001];
int f(int x, int y, int m) {
  if (y + m - 1 >= k) return 100000000;
  int res = 0;
  for (int i = (0); i < ((m)); ++i) {
    if (a[x][y + i]) return 100000000;
    res += abs(x - xc + 1) + abs(y + i - yc + 1);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  while (cin >> n >> k) {
    memset(a, 0, sizeof(a));
    xc = yc = (k + 1) / 2;
    while (n--) {
      int m;
      cin >> m;
      pair<int, pair<int, int> > res =
          make_pair(100000000, make_pair(100000000, 100000000));
      for (int i = (0); i < ((k)); ++i)
        for (int j = (0); j < ((k)); ++j) {
          pair<int, pair<int, int> > t = make_pair(f(i, j, m), make_pair(i, j));
          res = min(res, t);
        }
      if (res.first == 100000000) {
        cout << -1 << endl;
      } else {
        int x = res.second.first;
        int y = res.second.second;
        cout << x + 1 << " " << y + 1 << " " << y + m << endl;
        for (int i = (y); i < (y + m); ++i) a[x][i] = 1;
      }
    }
  }
  return 0;
}
