#include <bits/stdc++.h>
using namespace std;
long long int binExp(long long int a, long long int power,
                     long long int m = 1000000007) {
  long long int res = 1;
  while (power) {
    if (power & 1) res = (res * a) % m;
    a = (a * a) % m;
    power >>= 1;
  }
  return res;
}
int n, k;
int arr[100][100];
int cost[100][100];
void solve() {
  int q;
  cin >> n >> k;
  int c = (k + 1) / 2;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      arr[i][j] = arr[i][j - 1] + 1;
      cost[i][j] = abs(i - c) + abs(j - c) + cost[i][j - 1];
    }
  }
  while (n--) {
    int ele;
    cin >> ele;
    int x = -1, l = -1, r = -1;
    int mn = 1000000000;
    for (int row = 1; row <= k; row++) {
      for (int _l = 1, _r = ele; _r <= k; _l++, _r++) {
        if (arr[row][_r] - arr[row][_l - 1] == ele) {
          if (mn > cost[row][_r] - cost[row][_l - 1]) {
            mn = cost[row][_r] - cost[row][_l - 1];
            l = _l;
            r = _r;
            x = row;
          }
        }
      }
    }
    if (mn == 1000000000) {
      cout << -1 << "\n";
    } else {
      cout << x << " " << l << " " << r << "\n";
      for (int i = l; i <= r; i++) arr[x][i] -= i - l + 1;
      for (int i = r + 1; i <= k; i++) arr[x][i] -= ele;
    }
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
