import std.stdio, std.string, std.array, std.conv;

struct S {
    string name;
    int time;
}

struct T {
private:
    int n;
    S[] s;

public:
    this(int n) {
        this.s = new S[](n);
    }

    ulong length() {
        return s.length;
    }

    S front() {
        return s[0];
    }

    void pop() {
        s = s[1..$];
    }

    void push(S x) {
        s ~= x;
    }
}

void main() {
    int[] tmp = readln.chomp.split.to!(int[]);
    int n = tmp[0], q = tmp[1];
    T t = T(n);
    foreach (i; 0 .. n) {
        string[] process = readln.chomp.split;
        t.tupleof[1][i] = S(process[0], process[1].to!int);
    }
    int elaps = 0;
    while (t.length) {
        S s = t.front;
        t.pop;
        if (s.time > q) {
            elaps += q;
            t.push(S(s.name, s.time-q));
        } else {
            elaps += s.time;
            writeln(s.name, " ", elaps);
        }
    }
}
