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

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

void enqueue(P);
P dequeue(void);

P Q[LEN+1];
int head, tail, n;

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }
  while(head!=tail){
    u=dequeue();
    
  if(u.t>q){
    u.t-=q;
    elaps+=q;
  enqueue(u);
  }
  else{
    elaps+=u.t;
    printf("%s %d\n",u.name,elaps);
  }
  }

  
  return 0;
}

void enqueue(P x){
  if(head == (tail + 1) % (n+1)) exit(2);
  Q[tail] = x;
  if(tail + 1 == (n+1)) tail = 0;
  else tail++;
}

P dequeue(){
  P x;
  if(head == tail) exit(3);
  x = Q[head];
  if(head + 1 == (n+1)) head = 0;
  else head++;
  return x;			
}

