#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, xh;
  long long x;
  bool friend operator<(node a, node b) {
    if (a.x == b.x) {
      if (a.a == b.a) {
        if (a.b == b.b) return a.xh < b.xh;
        return a.b < b.b;
      }
      return a.a < b.a;
    }
    return a.x < b.x;
  }
  node() {}
  node(long long q, int w, int e, int r) { x = q, a = w, b = e, xh = r; }
} a[200010];
struct edge {
  int nex;
  node d;
} e[200010], e1[200010];
int n, m, t, i, l, r, efree1, tot, q1[200010], efree, q[200010];
long long j, ans[200010], nowi = 1, nowj;
set<node> sel, ser;
set<node>::iterator ii;
inline void add(int x, node y) {
  e[++efree].d = y;
  e[efree].nex = q[x];
  q[x] = efree;
}
inline void add1(int x, node y) {
  e1[++efree1].d = y;
  e1[efree1].nex = q1[x];
  q1[x] = efree1;
}
int main() {
  scanf("%d%d", &n, &m);
  a[n + 1].x = 1e18;
  for (i = 1; i <= n; i++)
    scanf(
        "%lld"
        "%d%d",
        &a[i].x, &a[i].a, &a[i].b),
        a[i].xh = i;
  sort(a + 1, a + 1 + n);
  if (a[1].a > 1)
    r++, ser.insert(node(a[1].a, a[1].a, a[1].b, a[1].xh)),
        add(a[1].a, node(a[1].a, a[1].a, a[1].b, a[1].xh));
  else if (a[1].a < 1)
    l++, sel.insert(node(a[1].a, a[1].a, a[1].b, a[1].xh)),
        add(a[1].a, node(a[1].a, a[1].a, a[1].b, a[1].xh));
  else {
    add1(a[1].b, node(a[1].b, a[1].b, a[1].b, a[1].xh));
    if (a[1].b > 1)
      r++, ser.insert(node(a[1].b, a[1].b, a[1].b, a[1].xh));
    else
      l++, sel.insert(node(a[1].b, a[1].b, a[1].b, a[1].xh));
  }
  for (i = 2; a[i].x == a[i - 1].x; i++) {
    if (a[i].a > 1)
      r++, ser.insert(node(a[i].a, a[i].a, a[i].b, a[i].xh)),
          add(a[i].a, node(a[i].a, a[i].a, a[i].b, a[i].xh));
    else if (a[i].a < 1)
      l++, sel.insert(node(a[i].a, a[i].a, a[i].b, a[i].xh)),
          add(a[i].a, node(a[i].a, a[i].a, a[i].b, a[i].xh));
    else {
      add1(a[i].b, node(a[i].b, a[i].b, a[i].b, a[i].xh));
      if (a[i].b > 1)
        r++, ser.insert(node(a[i].b, a[i].b, a[i].b, a[i].xh));
      else
        l++, sel.insert(node(a[i].b, a[i].b, a[i].b, a[i].xh));
    }
  }
  for (j = a[1].x;
       sel.begin() != sel.end() || ser.begin() != ser.end() || i <= n;) {
    while (j == a[i].x) {
      if (a[i].a > nowi)
        r++, ser.insert(node(a[i].a, a[i].a, a[i].b, a[i].xh)),
            add(a[i].a, node(a[i].a, a[i].a, a[i].b, a[i].xh));
      else if (a[i].a < nowi)
        l++, sel.insert(node(a[i].a, a[i].a, a[i].b, a[i].xh)),
            add(a[i].a, node(a[i].a, a[i].a, a[i].b, a[i].xh));
      else if (a[i].b > nowi)
        r++, ser.insert(node(a[i].b, a[i].b, a[i].b, a[i].xh)),
            add1(a[i].b, node(a[i].b, a[i].b, a[i].b, a[i].xh));
      else if (a[i].b < nowi)
        l++, sel.insert(node(a[i].b, a[i].b, a[i].b, a[i].xh)),
            add1(a[i].b, node(a[i].b, a[i].b, a[i].b, a[i].xh));
      i++;
    }
    for (; q[nowi]; q[nowi] = e[q[nowi]].nex) {
      if (sel.find(e[q[nowi]].d) != sel.end())
        l--, sel.erase(e[q[nowi]].d);
      else
        r--, ser.erase(e[q[nowi]].d);
      add1(e[q[nowi]].d.b, node(e[q[nowi]].d.b, e[q[nowi]].d.b, e[q[nowi]].d.b,
                                e[q[nowi]].d.xh));
      if (e[q[nowi]].d.b > nowi)
        r++, ser.insert(node(e[q[nowi]].d.b, e[q[nowi]].d.b, e[q[nowi]].d.b,
                             e[q[nowi]].d.xh));
      else
        l++, sel.insert(node(e[q[nowi]].d.b, e[q[nowi]].d.b, e[q[nowi]].d.b,
                             e[q[nowi]].d.xh));
    }
    for (; q1[nowi]; q1[nowi] = e1[q1[nowi]].nex) {
      ans[e1[q1[nowi]].d.xh] = j;
      if (sel.find(e1[q1[nowi]].d) != sel.end())
        l--, sel.erase(e1[q1[nowi]].d);
      else
        r--, ser.erase(e1[q1[nowi]].d);
    }
    if (r >= l && r) {
      ii = ser.begin();
      if (a[i].x - j == 0)
        nowj = (*ii).x - nowi;
      else if ((*ii).x - nowi == 0)
        nowj = a[i].x - j;
      else
        nowj = min((long long)(*ii).x - nowi, a[i].x - j);
      nowi += nowj;
      j += nowj;
    } else if (l) {
      ii = sel.end();
      ii--;
      if (a[i].x - j == 0)
        nowj = nowi - (*ii).x;
      else if (nowi - (*ii).x == 0)
        nowj = a[i].x - j;
      else
        nowj = min((long long)nowi - (*ii).x, a[i].x - j);
      nowi -= nowj;
      j += nowj;
    } else
      j = a[i].x;
  }
  for (i = 1; i <= n; i++)
    printf(
        "%lld"
        "\n",
        ans[i]);
  return 0;
}
