#include <bits/stdc++.h>
using namespace std;
int a[100][100] = {};
int k;
int cc(int ii, int f, int t) {
  int ans = 0;
  for (int x = (f); x < (t); x += (1)) {
    ans += abs((k + 1) / 2 - ii) + abs((k + 1) / 2 - x);
  }
  return ans;
}
int main() {
  int n = ({
    int x;
    scanf("%d", &x);
    x;
  });
  k = ({
    int x;
    scanf("%d", &x);
    x;
  });
  for (int i = (0); i < (n); i += (1)) {
    int s = ({
      int x;
      scanf("%d", &x);
      x;
    });
    int m = 1000000000;
    int ii, from, to;
    for (int i = (1); i < (k + 1); i += (1)) {
      for (int j = (1); j < (k - s + 2); j += (1)) {
        if (count(a[i] + j, a[i] + j + s, 1) == 0) {
          if (cc(i, j, j + s) < m) {
            m = cc(i, j, j + s);
            ii = i;
            from = j;
            to = j + s - 1;
          }
        }
      }
    }
    if (m == 1000000000) {
      cout << -1 << endl;
    } else {
      cout << ii << " " << from << " " << to << endl;
      for (int x = (from); x < (to + 1); x += (1)) {
        a[ii][x] = 1;
      }
    }
  }
  return 0;
}
