#include <bits/stdc++.h>
using namespace std;
int bitct(long long r) { return r == 0 ? 0 : (bitct(r >> 1) + (r & 1)); }
long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
template <typename T>
ostream& operator<<(ostream& o, vector<T> v) {
  o << "{";
  int i = 0, s = v.size();
  for (; i + 1 < s; i++) o << v[i] << ", ";
  if (s) o << v[i];
  o << "}";
  return o;
}
long long choose(long long n, long long q) {
  if (n == 0 || q == 0) return 1;
  if (q == 1)
    return n;
  else
    return (choose(n, q - 1) * (n - q + 1) / q);
}
vector<string> split(string& s, const string& d = " ") {
  vector<string> r;
  string t;
  for (int i = 0; i != s.size(); i++) {
    if (d.find(s[i]) != string::npos) {
      if (!t.empty()) {
        r.push_back(t);
        t = "";
      }
    } else {
      t += s[i];
    }
  }
  if (!t.empty()) {
    r.push_back(t);
  }
  return r;
}
vector<int> splitInt(string& s, const string& d = " ") {
  vector<string> t = split(s, d);
  vector<int> r;
  for (int i = 0; i != t.size(); i++) r.push_back(atoi(t[i].c_str()));
  return r;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int> > T(K, vector<int>(K, 0));
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;
    int bestDist = 1000000000;
    int bestx = 0;
    int besty = 0;
    int mid = K / 2;
    for (int x = 0; x < K; x++)
      for (int y = 0; y < K; y++) {
        if (T[x][y] || y + m > K) continue;
        int okay = 1;
        for (int i = 1; i < m; i++)
          if (T[x][y + i]) {
            okay = false;
            y = y + i + 1;
            break;
          }
        if (!okay) continue;
        int badness = 0;
        for (int i = 0; i < m; i++) badness += abs(x - mid) + abs(y + i - mid);
        if (badness < bestDist) {
          bestDist = badness;
          bestx = x;
          besty = y;
        }
      }
    if (bestDist > 1000000)
      cout << -1 << endl;
    else {
      cout << 1 + bestx << " " << 1 + besty << " " << 1 + besty + m - 1 << endl;
      for (int i = 0; i < m; i++) T[bestx][besty + i] = 1;
    }
  }
}
