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

typedef struct t{
  char name[10];
  int t;
} Process;

void enqueue(Process);
Process dequeue(void);
int min(int,int);

Process Q[LEN];
int head, tail, n;

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

void enqueue(Process x){
  Q[tail] = x;
  if (tail + 1 == LEN){
    tail = 0;
  }else{
    tail++;
  }
}


Process dequeue(){
  Process x = Q[head];
  if (head + 1 == LEN){
    head = 0;
  }else{
    head++;
  }
  return x;
}

//最小の値を返す
int min(int x,int y){
  if(x > y){
    return y;
  }else{
    return x;
  }
}

