#include <bits/stdc++.h>
using namespace std;
int check(vector<vector<bool> > &seat, int x, int y, int M) {
  int res = 0;
  int xc = seat.size() / 2;
  for (int j = y; j < y + M; j++) {
    if (seat[x][j]) return -1;
    res += abs(x - xc) + abs(j - xc);
  }
  return res;
}
int main(void) {
  int N, K;
  cin >> N >> K;
  vector<vector<bool> > seat(K, vector<bool>(K, false));
  for (int i = 0; i < N; i++) {
    int cost = 1E5;
    int x = -1, y = -1;
    int M;
    cin >> M;
    for (int j = 0; j < K; j++) {
      for (int k = 0; k <= K - M; k++) {
        int tmp;
        tmp = check(seat, j, k, M);
        if (tmp != -1 && tmp < cost) {
          cost = tmp;
          x = j;
          y = k;
        }
      }
    }
    if (x == -1 && y == -1) {
      cout << -1 << endl;
    } else {
      for (int j = y; j < y + M; j++) {
        seat[x][j] = true;
      }
      cout << x + 1 << " " << y + 1 << " " << y + M << endl;
    }
  }
}
