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

#define LEN 100005
#define TRUE 1
#define FALSE 0

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

int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

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

int main(){
  int elaps=0, c,d[LEN];
  int i,j,q;
  char e[100];
  P u;
  scanf("%d %d", &n, &q);

  for(i = 0;i < n;i++){
    scanf("%s",u.name);
    scanf("%d",u.t);
    enqueue(u);
  }

  i = 0;

  for(;;){
    u = dequeue();
    c = u.t - q;
    if(c > 0){
      elaps = elaps + q;
      u.t = c;
      enqueue(u);
    }
    else{
      elaps = elaps + u.t;
      d[i] = elaps;
      strcpy(e,u.name);
      printf("%s %d\n",e,d[i]);
      i++;
    }
    if(i == n - 1)break;
  }
  
  return 0;
}

int isEmpty(){
  if(head == tail){
    return TRUE;
  }
  else{
    return FALSE;
  }
}

int isFull(){
  if(head == (tail + 1) % n){
    return TRUE;
  }
  else{
    return FALSE;
  }
}

void enqueue(P x){
  int a;
  a = isFull();

  if(a == 1){
    printf("error\n");
  }
  else{
    Q[tail] = x;
    if(tail + 1 == n){
      tail = 0;
    }
    else{
      tail++;
    }
  }
}

P dequeue(){
  int b;
  P x;
  b = isEmpty();

  if(b == 1){
    printf("error\n");
  }
  else{
    x = Q[head];
    if(head + 1 == n){
      head = 0;
    }
    else{
      head++;
    }
  }

  return x;
}