#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<vector<int>> mp(K, vector<int>(K, 0));
  for (int i = 0; i < N; i++) {
    int M;
    cin >> M;
    int min = -1;
    int x = -1, yr = -1, yl = -1;
    for (int j = 0; j < K; j++) {
      for (int k = 0; k <= K - M; k++) {
        int tmp = 0;
        for (int l = 0; l < M; l++) {
          if (mp[j][k + l] == 1) {
            tmp = -1;
            break;
          } else {
            tmp += j > K / 2 ? j - K / 2 : K / 2 - j;
            tmp += k + l > K / 2 ? k + l - K / 2 : K / 2 - l - k;
          }
        }
        if (tmp != -1 && (min == -1 || min > tmp)) {
          min = tmp;
          x = j;
          yl = k;
          yr = k + M - 1;
        }
      }
    }
    if (x < 0) {
      cout << -1 << endl;
    } else {
      for (int l = 0; l < M; l++) {
        mp[x][yl + l] = 1;
      }
      cout << x + 1 << " " << yl + 1 << " " << yr + 1 << endl;
    }
  }
  return 0;
}
