#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:16000000")
const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 2 * acos(0.);
const int T = 1 << 17;
struct man {
  int t, s, f, num;
  void scan(int _num) {
    scanf("%d%d%d", &t, &s, &f);
    num = _num;
  }
};
bool cmp(man a, man b) { return a.t < b.t; }
man a[100500];
set<pair<int, int> > in, out;
set<int> S;
long long ans[100500];
int rsq[2 * T];
void add_val(int x, int val) {
  x += T;
  while (x > 0) {
    rsq[x] += val;
    x /= 2;
  }
}
int get_sum(int l, int r) {
  l += T;
  r += T;
  int ans = 0;
  while (l <= r) {
    if (l & 1) ans += rsq[l];
    if (!(r & 1)) ans += rsq[r];
    l = (l + 1) / 2;
    r = (r - 1) / 2;
  }
  return ans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    a[i].scan(i);
  }
  sort(a, a + n, cmp);
  long long curt = 0;
  int curf = 1;
  int p = 0;
  int q = 0;
  while (q < n) {
    while (p < n && a[p].t <= curt) {
      out.insert(pair<int, int>(a[p].s, p));
      add_val(a[p].s, 1);
      S.insert(a[p].s);
      p++;
    }
    S.erase(curf);
    set<pair<int, int> >::iterator iter =
        in.lower_bound(pair<int, int>(curf, 0));
    while (iter != in.end() && iter->first == curf) {
      ans[iter->second] = curt;
      ++q;
      add_val(iter->first, -1);
      in.erase(iter);
      iter = in.lower_bound(pair<int, int>(curf, 0));
    }
    iter = out.lower_bound(pair<int, int>(curf, 0));
    while (iter != out.end() && iter->first == curf) {
      in.insert(pair<int, int>(a[iter->second].f, a[iter->second].num));
      add_val(iter->first, -1);
      add_val(a[iter->second].f, 1);
      S.insert(a[iter->second].f);
      out.erase(iter);
      iter = out.lower_bound(pair<int, int>(curf, 0));
    }
    int pdown = get_sum(0, curf);
    int pup = get_sum(curf, m);
    if (pup == 0 && pdown == 0) {
      curt = a[p].t;
      continue;
    }
    int dt = a[p].t - curt;
    if (p == n) dt = m;
    int dir = 0;
    if (pup >= pdown) {
      set<int>::iterator iter = S.lower_bound(curf);
      dir = 1;
      dt = min(dt, (*iter) - curf);
    } else {
      set<int>::iterator iter = S.lower_bound(curf);
      dir = -1;
      --iter;
      dt = min(dt, curf - *iter);
    }
    curt += dt;
    curf += dir * dt;
  }
  for (int i = 0; i < n; ++i) {
    printf("%I64d\n", ans[i]);
  }
  return 0;
}
