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

public class bank_bm {
    FastScanner in;
    PrintWriter out;

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

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

        @Override
        public int compareTo(Person o) {
            if (o.t == t)
                return Long.compare(id, o.id);
            return Long.compare(t, o.t);
        }
    }

    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        Person[] a = new Person[n];
        for (int i = 0; i < n; i++) {
            a[i] = new Person(i, in.nextInt(), in.nextInt(), in.nextInt());
        }
        Arrays.sort(a);
        PriorityQueue<Person> one = new PriorityQueue<>();
        int free = m;
        Person[] second = new Person[n];
        int ss = 0;
        for (int i = 0; i < n; i++) {
            long startTime = a[i].t;
            if (free == 0) {
                second[ss++] = one.remove();
                free++;
                startTime = Math.max(startTime, second[ss - 1].t);
            }
            free--;
            a[i].t = startTime + a[i].a;
            one.add(a[i]);
        }
        while (one.size() > 0) {
            second[ss++] = one.remove();
        }
        Arrays.sort(second);
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            if (i > 0)
                second[i].t = Math.max(second[i].t, second[i - 1].t);
            second[i].t += second[i].b;
            res[(int) second[i].id] = second[i].t;
        }
        for (int i = 0; i < n; i++)
            out.println(res[i]);
    }

    void run() {
        try {
            in = new FastScanner(new File("bank.in"));
            out = new PrintWriter(new File("bank.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }

    public static void main(String[] args) {
        new bank_bm().run();
    }
}