#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const long double pi = 3.14159265358979323846;
const long long mod = 1000000007;
bool cinema[100][100];
int main() {
  ios::sync_with_stdio(false);
  int n, k, xc, yc;
  cin >> n >> k;
  xc = yc = (k + 1) / 2;
  for (int i = 0; i < n; ++i) {
    int M, Min = INF, x = -1, l, r;
    cin >> M;
    for (int j = 1; j <= k; ++j) {
      for (int z = 1; z <= k - M + 1; ++z) {
        bool ok = true;
        int sum = 0;
        for (int u = z; u <= z + M - 1 && ok; ++u) {
          if (cinema[j][u]) {
            ok = false;
            break;
          }
          sum += abs(u - xc) + abs(j - yc);
        }
        if (!ok) continue;
        if (Min > sum) {
          Min = sum;
          x = j;
          l = z;
          r = z + M - 1;
        }
      }
    }
    if (x == -1)
      cout << x << endl;
    else {
      for (int j = l; j <= r; ++j) cinema[x][j] = true;
      cout << x << ' ' << l << ' ' << r << endl;
    }
  }
  return 0;
}
