#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> a;
long long n;
long long X, Y;
vector<long long> check(long long x) {
  long long mn = 1e9, left, row;
  for (long long rad = 1; rad <= n; ++rad) {
    long long sum = 0, free = 0;
    for (long long i = 1; i < x; ++i)
      free += (a[rad][i] == 0), sum += abs(X - rad) + abs(Y - i);
    for (long long r = x; r <= n; ++r) {
      free += (a[rad][r] == 0);
      sum += abs(X - rad) + abs(Y - r);
      if (free == x && sum < mn) {
        mn = sum;
        left = (r - x) + 1;
        row = rad;
      }
      free -= (a[rad][r - x + 1] == 0);
      sum -= abs(X - rad) + abs(Y - (r - x + 1));
    }
  }
  if (mn == 1e9)
    return {-1};
  else {
    for (long long i = left; i <= left + x - 1; ++i) a[row][i] = true;
    return {row, left, left + x - 1};
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q >> n;
  a.resize(n + 1, vector<long long>(n + 1));
  X = n / 2 + 1;
  Y = X;
  while (q--) {
    long long m;
    cin >> m;
    vector<long long> tmp = check(m);
    if (tmp[0] == -1)
      cout << -1 << '\n';
    else {
      for (auto i : tmp) cout << i << ' ';
      cout << '\n';
    }
  }
}
