#include <bits/stdc++.h>
using namespace std;
long long s[101][101];
signed main() {
  long long n, k, xc, yc;
  vector<long long> a(1001);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  xc = (ceil(double(k) / double(2))), yc = (ceil(double(k) / double(2)));
  for (long long d = 1; d <= n; d++) {
    long long Tfuc = INT_MAX, mx = -1, my1 = -1, my2 = -1;
    for (long long i = 1; i <= k; i++) {
      long long ly = 1, len = 0, fuc = 0, tt = 0;
      for (long long j = 1; j <= k; j++) {
        len++;
        fuc += (abs(i - xc) + abs(j - yc));
        if (s[i][j] == 0) tt++;
        if (len == a[d]) {
          if (fuc < Tfuc && tt == a[d]) {
            mx = i;
            my1 = j - a[d] + 1;
            my2 = j;
            Tfuc = fuc;
          }
          len--;
          fuc -= (abs(i - xc) + abs(yc - ly));
          if (s[i][ly] == 0) tt--;
          ly++;
        }
      }
    }
    if (mx != -1) {
      for (long long j = my1; j <= my2; j++) {
        s[mx][j] = 1;
      }
    }
    if (mx == -1)
      cout << "-1\n";
    else
      cout << mx << " " << my1 << " " << my2 << "\n";
  }
}
