#include <bits/stdc++.h>
int n, k;
int xc, yc;
int tot[111];
short int sum[111][111];
int abs(int a) { return a > 0 ? a : -a; }
void solve(int m) {
  if (m > k) {
    puts("-1");
    return;
  }
  int mn = 1000000000, x, yl, yr;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k - m + 1; j++)
      if (sum[i][j + m - 1] - sum[i][j - 1] == 0) {
        int ans = tot[j + m - 1] - tot[j - 1] + abs(xc - i) * m;
        if (ans < mn) mn = ans, x = i, yl = j, yr = j + m - 1;
      }
  }
  if (mn == 1000000000) {
    puts("-1");
    return;
  }
  printf("%d %d %d\n", x, yl, yr);
  for (int j = yl; j <= yr; j++) sum[x][j] = sum[x][j - 1] + 1;
  for (int j = yr + 1; j <= k; j++) sum[x][j] += m;
}
int main() {
  scanf("%d %d", &n, &k);
  xc = yc = (k + 1) / 2;
  tot[0] = 0;
  for (int i = 1; i <= k; i++) tot[i] = tot[i - 1] + abs(xc - i);
  for (int i = 0; i < n; i++) {
    int m;
    scanf("%d", &m);
    solve(m);
  }
}
