#include <bits/stdc++.h>
using namespace std;
const int maxn = 40000 + 1;
int n, k, xmid, ymid, dis = -1;
bool mark[1000][1000];
int check(int x, int y, int num) {
  for (int i = 0; i < num; i++)
    if (mark[x][y + i] || y + i >= k) return -1;
  int cnt = 0;
  for (int i = 0; i < num; i++) cnt += abs(x - xmid) + abs(y + i - ymid);
  return cnt;
}
int main() {
  cin >> n >> k;
  xmid = k / 2;
  ymid = k / 2;
  int num;
  for (int i = 0; i < n; i++) {
    cin >> num;
    dis = -1;
    int xans, yans;
    for (int j = 0; j < k; j++)
      for (int p = 0; p < k - num + 1; p++) {
        int tmp = check(j, p, num);
        if (tmp != -1)
          if (dis == -1 || dis > tmp) {
            dis = tmp;
            xans = j;
            yans = p;
          }
      }
    if (dis == -1)
      cout << "-1\n";
    else {
      cout << xans + 1 << " " << yans + 1 << " " << yans + num << "\n";
      for (int j = 0; j < num; j++) mark[xans][yans + j] = 1;
    }
  }
  return 0;
}
