//#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#define mp make_pair
#define pb push_back

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", clock()*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, clock()*1.0/CLOCKS_PER_SEC)

#if ( _WIN32 || __WIN32__ )
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

using namespace std;

#define TASKNAME "bank"

#ifdef LOCAL
static struct __timestamper {
	~__timestamper(){
        TIMESTAMP(end);
	}
} __TIMESTAMPER;
#endif

typedef long long ll;
typedef long double ld;

                     
int t[2][100000];

enum eventType { _COME = 0, _OUT1 = 1, _OUT2 = 2};

struct event{
	eventType ty;
	ll tm;
	int id;
	event(eventType ty, ll tm, int id): ty(ty), tm(tm), id(id){
	}
	bool operator<(const event& r) const{
		if (tm != r.tm)
			return tm < r.tm;
		return id < r.id;
	}
};


queue<int> q[2];
int cnt[2];

set<event> evs;

int m[2];
ll ans[110000];

int main(){
    freopen(TASKNAME".in","r",stdin);
    freopen(TASKNAME".out","w",stdout);

    int n;
    scanf("%d %d", &n, &m[0]);
    m[1] = 1;
    for (int i = 0; i < n; i++){
    	int tin;
    	scanf("%d %d %d",&tin, &t[0][i], &t[1][i]);
    	evs.insert(event(_COME, tin, i));
    }

    while (!evs.empty()){
		event cur = *evs.begin();
		evs.erase(evs.begin());
		if (cur.ty == _COME){
			if (t[0][cur.id] != 0)
				q[0].push(cur.id);
			else if (t[1][cur.id] != 0)
				q[1].push(cur.id);
			else
			    ans[cur.id] = cur.tm;			    
		} else if (cur.ty == _OUT1){
			cnt[0]--;
			if (t[1][cur.id] != 0)
				q[1].push(cur.id);
			else
			    ans[cur.id] = cur.tm;			    
		} else if (cur.ty == _OUT2){
			cnt[1]--;
			ans[cur.id] = cur.tm;
		}
		for (int i = 0; i < 2; i++)
			while (cnt[i] < m[i] && !q[i].empty()){
				int v = q[i].front(); q[i].pop();
				cnt[i]++;
				evs.insert(event(eventType(i + _OUT1), cur.tm + t[i][v], v));
			}
    }

    for (int i = 0; i < n; i++)
    	printf(LLD"\n", ans[i]);
     
    return 0;
}