#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100005

typedef struct pp{
  char name[100];
  int time;
}P;

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

void enqueue(P);
P dequeue(void);
int min(int a,int b){return a<b ? a:b;};

int main(){
  int x,q,sum,lap=0,a;
  P u;

  scanf("%d%d",&n,&q);
  tail=n+1;

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

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

P dequeue(){
  P x =Q[head];
  head=(head+1)%N;
  return x;
}
