#include <bits/stdc++.h>
using namespace std;
int N, K, M;
int grid[100][100];
int main(int argc, char** argv) {
  cin >> N >> K;
  int center = K / 2;
  memset(grid, 0, sizeof(grid));
  while (N--) {
    cin >> M;
    double minX = -1;
    double minY = -1;
    int minScore;
    for (int i = 0; i < K; i++) {
      int len = 0;
      int minVal = -1;
      for (int j = 0; j < K; j++) {
        if (grid[i][j] == 1)
          len = 0;
        else
          len++;
        if (len >= M) {
          int mid = (j + j - M + 1);
          if (minVal == -1 ||
              abs(2 * center - mid) < abs(2 * center - minVal)) {
            minVal = mid;
          }
        }
      }
      if (minVal == -1) continue;
      int scr = 0;
      int left = (minVal - M + 1) / 2;
      int right = left + M - 1;
      for (int k = left; k <= right; k++)
        scr += abs(k - center) + abs(i - center);
      if (minX == -1 || scr < minScore)
        minX = i, minY = (double)minVal / 2.0, minScore = scr;
    }
    if (minX == -1)
      cout << -1 << endl;
    else {
      int left = minY - (M - 1) / 2;
      int right = left + M - 1;
      int row = (int)minX;
      for (int i = left; i <= right; i++) grid[row][i] = 1;
      cout << row + 1 << " " << left + 1 << " " << right + 1 << endl;
    }
  }
  return (EXIT_SUCCESS);
}
