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

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

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

void enqueue(PP x);
PP dequeue();
int min(int a,int b);

int main(){
  int elaps=0,c;
  int i,q;
  PP z;

  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){
    z=dequeue();
    c=min(q,z.time);
    z.time-=c;
    elaps+=c;
    if(z.time>0) enqueue(z);
    else printf("%s %d\n",z.name,elaps);
  }
  return 0;
}

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

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

int min(int a,int b){
  int min;
  if(a<b) min=a;
  else if(b<a) min=b;
  return min;
}
