#include <bits/stdc++.h>
void gogo() {
  int n = 0, k = 0;
  int DP[101][101];
  scanf("%d %d", &n, &k);
  for (int i = 0; i < k; ++i)
    for (int j = 0; j < k; ++j) DP[i][j] = 0;
  for (int i = 0; i < n; ++i) {
    int query = 0;
    scanf("%d", &query);
    int best = 1000000000;
    int x, y1, y2;
    int xc = (k + 1) / 2 - 1, yc = (k + 1) / 2 - 1;
    for (int j = 0; j < k; ++j) {
      for (int h = 0; h + query <= k; ++h) {
        int cost = 0, count = 0;
        for (int g = h; g < h + query; ++g) {
          cost += abs(xc - j) + abs(yc - g);
          count += DP[j][g] == 0;
        }
        if (cost < best && count == query) {
          best = cost;
          x = j;
          y1 = h;
          y2 = h + query - 1;
        }
      }
    }
    if (best == 1000000000)
      printf("-1\n");
    else {
      for (int j = y1; j <= y2; ++j) DP[x][j] = 1;
      printf("%d %d %d\n", x + 1, y1 + 1, y2 + 1);
    }
  }
}
int main() {
  gogo();
  return 0;
}
