#include<stdio.h>
#define datamax 100001
typedef struct{
  char name[11];
  int time;
}PROCESS;
PROCESS queue[datamax];
void inqueue(PROCESS);
PROCESS dequeue(void);
int min(int,int);
int head,tail;
int main(){
  int n,q,ans=0,i;
  PROCESS temp;
  int calc;
  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",queue[i].name,&queue[i].time);
  }
  head = 0; tail=n;
  while(head != tail){
    temp = dequeue();
    calc = min(temp.time,q);
    ans += calc;
    temp.time = temp.time - calc;
    if(temp.time > 0)inqueue(temp);
    else{
      printf("%s %d\n",temp.name,ans);
    }
  }

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

void inqueue(PROCESS x){
  queue[tail] = x;
  tail = (tail + 1) % datamax;
}

PROCESS dequeue(){
  PROCESS temp;
  temp = queue[head];
  head = (head +1) % datamax;
  return temp;
}

