#include <bits/stdc++.h>
using namespace std;
bool a[101][101];
int main() {
  int n, k;
  int m;
  cin >> n >> k;
  int xx = (k + 1) >> 1, yy = (k + 1) >> 1;
  while (n--) {
    cin >> m;
    int x, y, min = INT32_MAX;
    for (int i = 1; i <= k; ++i) {
      for (int j = 1; j <= k - m + 1; ++j) {
        bool flag = true;
        int sum = 0;
        for (int l = j; l < j + m; ++l) {
          if (a[i][l]) {
            flag = false;
            break;
          }
          sum += abs(i - xx) + abs(l - yy);
        }
        if (flag && sum < min) min = sum, x = i, y = j;
      }
    }
    if (min == INT32_MAX)
      cout << -1 << endl;
    else {
      for (int j = y; j < y + m; ++j) a[x][j] = 1;
      printf("%d %d %d\n", x, y, y + m - 1);
    }
  }
  return 0;
}
