#include <bits/stdc++.h>
using namespace std;
struct Segtree {
  int left[100010 * 4], right[100010 * 4];
  int L[100010 * 4], R[100010 * 4];
  int sum[100010 * 4];
  void build(int l, int r, int step) {
    left[step] = l, right[step] = r;
    sum[step] = 0;
    L[step] = R[step] = -1;
    if (l == r) return;
    int mid = (l + r) / 2;
    build(l, mid, step * 2);
    build(mid + 1, r, step * 2 + 1);
  }
  void updata(int w, int num, int step) {
    if (left[step] == right[step]) {
      sum[step] += num;
      L[step] = R[step] = sum[step] ? w : -1;
      return;
    }
    int mid = (left[step] + right[step]) / 2;
    updata(w, num, w <= mid ? (step * 2) : (step * 2 + 1));
    sum[step] = sum[step * 2] + sum[step * 2 + 1];
    L[step] = L[step * 2 + (L[step * 2] == -1 ? 1 : 0)];
    R[step] = R[step * 2 + (R[step * 2 + 1] == -1 ? 0 : 1)];
  }
  int ask(int l, int r, int &g, int &h, int step) {
    if (left[step] == l && right[step] == r) {
      g = L[step], h = R[step];
      return sum[step];
    }
    int mid = (left[step] + right[step]) / 2;
    if (r <= mid)
      return ask(l, r, g, h, step * 2);
    else if (l > mid)
      return ask(l, r, g, h, step * 2 + 1);
    else {
      int g1, g2, h1, h2;
      int ret =
          ask(l, mid, g1, h1, step * 2) + ask(mid + 1, r, g2, h2, step * 2 + 1);
      g = g1 != -1 ? g1 : g2;
      h = h2 != -1 ? h2 : h1;
      return ret;
    }
  }
} tree;
int n, m;
struct People {
  int t, s, f, id;
  void init(int _id) {
    id = _id;
    scanf("%d%d%d", &t, &s, &f);
  }
  bool friend operator<(const People &a, const People &b) { return a.t < b.t; }
} data[100010];
map<int, vector<int> > mm;
long long ans[100010], now;
void updata(int cur) {
  for (__typeof(mm[cur].begin()) iter = mm[cur].begin(); iter != mm[cur].end();
       iter++) {
    int k = *iter;
    if (k >= 0) {
      mm[data[k].f].push_back(-data[k].id);
      tree.updata(data[k].f, 1, 1);
    } else
      ans[-k] = now;
  }
  tree.updata(cur, -((int)mm[cur].size()), 1);
  mm[cur].clear();
}
int main() {
  scanf("%d%d", &n, &m);
  tree.build(1, m, 1);
  for (int i = 0; i < n; i++) data[i].init(i + 1);
  sort(data, data + n);
  int cur = 1, i = 0, g1, h1, g2, h2;
  while (true) {
    int num1 = tree.ask(1, cur, g1, h1, 1), num2 = tree.ask(cur, m, g2, h2, 1);
    if (num1 > num2) {
      if (i < n && data[i].t <= now + cur - h1) {
        cur = cur - (data[i].t - now);
        now = data[i].t;
        mm[data[i].s].push_back(i);
        tree.updata(data[i].s, 1, 1);
        i++;
        continue;
      }
      now += cur - h1;
      cur = h1;
      updata(cur);
    } else if (num1 <= num2 && num2) {
      if (i < n && data[i].t <= now + g2 - cur) {
        cur = cur + (data[i].t - now);
        now = data[i].t;
        mm[data[i].s].push_back(i);
        tree.updata(data[i].s, 1, 1);
        i++;
        continue;
      }
      now += g2 - cur;
      cur = g2;
      updata(cur);
    } else {
      if (i == n) break;
      now = data[i].t;
      mm[data[i].s].push_back(i);
      tree.updata(data[i].s, 1, 1);
      i++;
    }
  }
  for (int i = 0; i < n; i++) printf("%I64d\n", ans[i + 1]);
  return 0;
}
