#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int xc = (k + 1) / 2;
  long long int yc = (k + 1) / 2;
  int a[k + 1][k + 1];
  memset(a, 0, sizeof(a));
  while (n--) {
    long long int m, mn = INT_MAX, X = 0, Y = 0;
    cin >> m;
    for (long long int i = 1; i < k + 1; i++) {
      for (long long int j = 1; j <= k - m + 1; j++) {
        long long int f = 0;
        long long int s = 0;
        for (long long int t = j; t <= j + m - 1; t++) {
          if (a[i][t] == 1) {
            f = 1;
            break;
          }
          s += abs(i - xc) + abs(t - yc);
        }
        if (f == 0 && s < mn) {
          mn = s;
          X = i;
          Y = j;
        }
      }
    }
    if (mn == INT_MAX) {
      cout << -1 << endl;
    } else {
      for (long long int t = Y; t < Y + m; t++) a[X][t] = 1;
      cout << X << " " << Y << " " << Y + m - 1 << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
