#include <bits/stdc++.h>
using namespace std;
const int maxk = 99 + 5;
const int INF = 0x3f3f3f3f;
int N, K;
int vis[maxk][maxk];
int G[maxk][maxk];
int val[maxk][maxk];
int sum1(int x, int y1, int y2) {
  if (!y1) return val[x][y2];
  return val[x][y2] - val[x][y1 - 1];
}
int sum2(int x, int y1, int y2) {
  if (!y1) return vis[x][y2];
  return vis[x][y2] - vis[x][y1 - 1];
}
int main() {
  while (cin >> N >> K) {
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < K; i++)
      for (int j = 0; j < K; j++) val[i][j] = abs(i - K / 2) + abs(j - K / 2);
    for (int i = 0; i < K; i++)
      for (int j = 1; j < K; j++) val[i][j] += val[i][j - 1];
    while (N--) {
      int M;
      scanf("%d", &M);
      int ans = INF;
      int a = -1, b = -1;
      for (int i = 0; i < K; i++)
        for (int j = 0; j < K - M + 1; j++)
          if (sum2(i, j, j + M - 1) == 0)
            if (sum1(i, j, j + M - 1) < ans) {
              ans = sum1(i, j, j + M - 1);
              a = i;
              b = j;
            }
      if (a == -1) {
        cout << -1 << endl;
        continue;
      }
      cout << a + 1 << ' ' << b + 1 << ' ' << b + M << endl;
      for (int i = b; i < b + M; i++) G[a][i] = 1;
      vis[a][0] = G[a][0];
      for (int i = 1; i < K; i++) vis[a][i] = vis[a][i - 1] + G[a][i];
    }
  }
  return 0;
}
