#include <bits/stdc++.h>
using namespace std;
string lower(string s) {
  for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
  return s;
}
vector<string> sep(string s, char c) {
  string temp;
  vector<string> res;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == c) {
      if (temp != "") res.push_back(temp);
      temp = "";
      continue;
    }
    temp = temp + s[i];
  }
  if (temp != "") res.push_back(temp);
  return res;
}
template <class T>
T toint(string s) {
  stringstream s1(s);
  T n;
  s1 >> n;
  return n;
}
template <class T>
string tostr(T n) {
  stringstream s;
  s << n;
  return s.str();
}
template <class T>
void D(T A[], int n) {
  for (int i = 0; i < n; i++) cout << A[i] << " ";
  cout << endl;
}
template <class T>
void D(vector<T> A, int n = -1) {
  if (n == -1) n = A.size();
  for (int i = 0; i < n; i++) cout << A[i] << " ";
  cout << endl;
}
bool mp[101][101];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  memset(mp, 0, sizeof(mp));
  int cx, cy;
  cx = (k + 1) / 2;
  cy = (k + 1) / 2;
  for (int(i) = (0); (i) < (n); (i)++) {
    int m;
    scanf("%d", &m);
    int rsum = -1;
    int ccx;
    int ccy;
    for (int(x) = (1); (x) <= (k); (x)++) {
      int lastc = 0;
      int sum = 0;
      for (int(y) = (1); (y) <= (k); (y)++) {
        sum += abs(x - cx) + abs(y - cy);
        if (!mp[x][y])
          lastc++;
        else {
          lastc = 0;
          sum = 0;
          continue;
        }
        if (lastc > m) {
          sum -= abs(x - cx) + abs((y - (m)) - cy);
          lastc = m;
        }
        if (lastc == m) {
          if (rsum == -1 || sum < rsum) {
            rsum = sum;
            ccx = x;
            ccy = y;
          }
        }
      }
    }
    if (rsum == -1) {
      puts("-1");
      continue;
    } else {
      printf("%d %d %d\n", ccx, ccy - m + 1, ccy);
      for (int(t) = (ccy - m + 1); (t) <= (ccy); (t)++) mp[ccx][t] = 1;
    }
  }
  return 0;
}
