#include <bits/stdc++.h>
using namespace std;
int n, m;
long long an[100010];
struct epoch {
  int st, x, y, id, u, d;
} a[100010];
set<int> c;
set<int> d[2][100010];
bool cmp(epoch a, epoch b) { return a.st < b.st; }
void solve() {
  int top = 1, f = 0, cur = 1, U = 0, D = 0, nxt;
  long long now = 0, t1;
  for (; top <= n || !c.empty();) {
    if (U + D == 0)
      t1 = 100000000000000007LL, f = 0;
    else {
      if (U >= D)
        nxt = *c.lower_bound(cur), f = 1, t1 = now + nxt - cur;
      else
        nxt = -(*c.lower_bound(-cur)), f = -1, t1 = now + cur - nxt;
    }
    if (top <= n && a[top].st <= t1) {
      cur += f * (a[top].st - now);
      now = a[top].st;
      d[0][a[top].x].insert(top);
      if (d[0][a[top].x].size() == 1) c.insert(a[top].x), c.insert(-a[top].x);
      if (a[top].x >= cur)
        ++U, a[top].u = 1;
      else
        ++D, a[top].d = 1;
      ++top;
    } else {
      while (d[0][nxt].size()) {
        int tmp = *d[0][nxt].upper_bound(0);
        U -= a[tmp].u, D -= a[tmp].d;
        d[1][a[tmp].y].insert(tmp);
        if (d[1][a[tmp].y].size() == 1) c.insert(a[tmp].y), c.insert(-a[tmp].y);
        if (a[tmp].y >= nxt)
          ++U, a[tmp].u = 1, a[tmp].d = 0;
        else
          ++D, a[tmp].u = 0, a[tmp].d = 1;
        d[0][nxt].erase(tmp);
      }
      while (d[1][nxt].size()) {
        int tmp = *d[1][nxt].upper_bound(0);
        U -= a[tmp].u, D -= a[tmp].d;
        an[a[tmp].id] = t1;
        d[1][nxt].erase(tmp);
      }
      c.erase(nxt), c.erase(-nxt);
      now = t1, cur = nxt;
    }
  }
  for (int i = 1; i <= n; ++i) printf("%I64d\n", an[i]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
    scanf("%d%d%d", &a[i].st, &a[i].x, &a[i].y), a[i].id = i;
  sort(a + 1, a + n + 1, cmp);
  solve();
  return 0;
}
