#include <bits/stdc++.h>
using namespace std;
bool seat[100][100] = {0};
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  while (n--) {
    int num, x, l, r, min_sum;
    min_sum = 100000;
    scanf("%d", &num);
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k - num + 1; j++) {
        int flag, sum;
        sum = 0;
        flag = 0;
        for (int m = j; m <= j + num - 1; m++) {
          if (seat[i][m]) {
            flag = 1;
            break;
          }
          sum += abs(i - k / 2 - 1) + abs(m - k / 2 - 1);
        }
        if (flag == 0 && sum < min_sum) {
          x = i;
          l = j;
          r = j + num - 1;
          min_sum = sum;
        }
      }
    }
    if (min_sum == 100000)
      printf("-1\n");
    else {
      printf("%d %d %d\n", x, l, r);
      for (int i = l; i <= r; i++) seat[x][i] = 1;
    }
  }
  return 0;
}
