#include <bits/stdc++.h>
using namespace std;
bool a[110][110];
int main() {
  int n, k;
  cin >> n >> k;
  int xc = (k + 1) / 2, yc = (k + 1) / 2;
  while (n--) {
    int x;
    cin >> x;
    int X, Y, Min = 2147483647;
    for (int i = 1; i <= k; i++) {
      for (int j = 1; j <= k - x + 1; j++) {
        bool f = 1;
        int s = 0;
        for (int k = j; k < j + x; k++) {
          if (a[i][k]) {
            f = 0;
            break;
          }
          s += abs(i - xc) + abs(k - yc);
        }
        if (f && s < Min) {
          Min = s;
          X = i;
          Y = j;
        }
      }
    }
    if (Min == 2147483647)
      cout << "-1" << endl;
    else {
      for (int i = Y; i < Y + x; i++) a[X][i] = 1;
      cout << X << " " << Y << " " << Y + x - 1 << endl;
    }
  }
  return 0;
}
