#include <bits/stdc++.h>
using namespace std;
bool a[110][110];
long long n, k, xc, yc, x;
int id() {
  int X = 0, w = 1;
  char c;
  c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    X = (X << 3) + (X << 1) + c - '0';
    c = getchar();
  }
  return X * w;
}
int main() {
  n = id();
  k = id();
  xc = yc = (k + 1) / 2;
  while (n--) {
    x = id();
    long long X, Y, Min = 9223372036854775807;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k - x + 1; j++) {
        bool f = 1;
        int s = 0;
        for (int t = j; t < j + x; t++) {
          if (a[i][t] > 0) {
            f = 0;
            break;
          }
          s += abs(xc - i) + abs(yc - t);
        }
        if (f && s < Min) Min = s, X = i, Y = j;
      }
    if (Min == 9223372036854775807)
      cout << "-1" << endl;
    else {
      for (int i = Y; i < Y + x; i++) a[X][i] = 1;
      cout << X << " " << Y << " " << Y + x - 1 << "\n";
    }
  }
}
