#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[1010][1010];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    int px = (k + 1) / 2;
    int py = (k + 1) / 2;
    int ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 1e9;
    for (int i = 1; i <= k; ++i)
      for (int j = 1; j <= k - x + 1; ++j) {
        int sum = 0, flag = 1;
        ;
        for (int t = j; t < j + x; ++t) {
          if (a[i][t]) {
            flag = 0;
            break;
          }
          sum += abs(t - py) + abs(i - px);
        }
        if (flag == 1 && sum < ans4)
          ans4 = sum, ans1 = i, ans2 = j, ans3 = j + x - 1;
      }
    if (ans4 == 1e9)
      cout << -1 << endl;
    else {
      for (int i = ans2; i <= ans3; ++i) a[ans1][i] = 1;
      cout << ans1 << " " << ans2 << " " << ans3 << endl;
    }
  }
  return 0;
}
