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

class Process {
  static int cpuTime = 0;
  string name;
  int time;

  this(string name, int time) {
    this.name = name;
    this.time = time;
  }
}

void main() {
  int n, q;

  readf("%d %d\n", &n, &q);

  auto process = new Process[n];

  for (int i = 0; i < n; i++) {
    auto input = readln.chomp.split;
    process[i] = new Process(input[0], input[1].to!int);
  }

  while (!process.empty) {
    auto currentP = process.front;
    process.popFront;

    if (currentP.time <= q) {
      Process.cpuTime += currentP.time;
      writefln("%s %d", currentP.name, Process.cpuTime);
    } else {
      currentP.time -= q;
      Process.cpuTime += q;
      process ~= currentP;
    }
  }
}