import java.io.*;
import java.util.*;

public class bank_va implements Runnable {
	public static void main(String[] args) {
		new Thread(new bank_va()).run();
	}

	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}

		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public class Person implements Comparable<Person> {
		int id, a, b;
		long t;

		public Person(int id, int t, int a, int b) {
			this.id = id;
			this.t = t;
			this.a = a;
			this.b = b;
		}

		public int compareTo(Person p) {
			return p.t == t ? id - p.id : Long.signum(t - p.t);
		}

		public String toString() {
			return id + " " + t;
		}
	}

	public void solve() throws IOException {
		int n = nextInt();
		int m = nextInt();

		TreeSet<Person> window = new TreeSet<Person>();

		Person[] p = new Person[n];
		for (int i = 0; i < p.length; i++) {
			p[i] = new Person(i, nextInt(), nextInt(), nextInt());
		}

		for (int i = 0; i < p.length; i++) {
			if (p[i].a != 0) {
				long time = p[i].t;
				if (window.size() == m) {
					Person x = window.pollFirst();
					time = Math.max(time, x.t);
				}
				p[i].t = time + p[i].a;
				window.add(p[i]);
			}
		}

		Arrays.sort(p);
		// System.err.println(Arrays.toString(p));

		long[] ans = new long[n];
		long time = 0;
		for (int i = 0; i < p.length; i++) {
			if (p[i].b == 0) {
				ans[p[i].id] = p[i].t;
			} else {
				p[i].t = Math.max(p[i].t, time) + p[i].b;
				time = p[i].t;
				ans[p[i].id] = p[i].t;
			}
		}

		for (int i = 0; i < ans.length; i++) {
			out.println(ans[i]);
		}
	}

	public void run() {
		try {
			br = new BufferedReader(new FileReader("bank.in"));
			out = new PrintWriter("bank.out");

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}
