#include<stdio.h>
#include<string.h>
#define N 100000

typedef struct p{
  char name[11];
  int time;
}P;

P Q[N+1];
int head, tail, n;

void enqueue(P x){
    int next = (tail + 1) % N;
    Q[tail] = x;
    tail = next;
}

P dequeue(){
    P x;
    x = Q[head];
    head = (head + 1) % N;
    return x;
}
int min(int a, int b) { 
    if(a < b) return a;
    else return b; 
}
int main(){
  int time = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }
  head = 1;
  tail = n + 1;
  while(head != tail){
    u = dequeue();
    c = min(q, u.time);
    u.time -= c;
    time += c;
    if ( u.time > 0 ) enqueue(u);
    else printf("%s %d\n", u.name,time);
  }
  
  return 0;
}
