#include <stdio.h>
#define MAX 100000

typedef struct{
  char name[10];
  int time;
} status;
status cpu[MAX];
int q;

void enqueue(status);
status  dequeue();
int compare(int,int);

int head=0,tail;

int main(){
  int i,n,q,count=0,checkcount=0;
  status x;
  scanf("%d%d",&n,&q);
  for(i=0; i<n; i++){
    scanf("%s%d",cpu[i].name,&cpu[i].time);
  }
  tail = n;
  while(1){
    if(head == tail) break;
    x  = dequeue();
    count = compare(q,x.time);
    x.time -= count;
    checkcount += count;
    if(x.time > 0) enqueue(x);
    else printf("%s %d\n",x.name,checkcount);
  }

  return 0;
}

void enqueue(status x){
  cpu[tail] = x;
  tail = (tail + 1) % MAX; 
}

status dequeue(){
  status x;
  x = cpu[head];
  head = (head + 1) % MAX;
  return x;
}

int compare(int a,int b){
  return a < b ? a : b;
}