#include <bits/stdc++.h>
int a[101][101];
int main() {
  int n, k, min, c, m, i, sum, x, l, r, smin, j;
  scanf("%d%d", &n, &k);
  c = (k + 1) / 2;
  while (n--) {
    min = 99000;
    scanf("%d", &m);
    for (i = 1; i <= k; i++) {
      smin = 0;
      sum = 0;
      for (j = 1; j <= k; j++) {
        if (a[i][j] == 0) {
          sum++;
          smin += abs(j - c) + abs(i - c);
          if (sum > m) smin -= (abs(j - m - c) + abs(i - c));
        } else {
          sum = 0;
          smin = 0;
        }
        if (sum >= m && smin < min) {
          x = i;
          l = j - m + 1;
          r = j;
          min = smin;
        }
      }
    }
    if (min == 99000)
      printf("-1\n");
    else {
      printf("%d %d %d\n", x, l, r);
      for (i = l; i <= r; i++) a[x][i] = 1;
    }
  }
  return 0;
}
