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

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

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

void initialize();
bool isEnpty();
bool isFull();
void enqueue(P);
P dequeue();


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

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  initialize();

  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 initialize(){
    head=0;
    tail=n;
}

bool isEnpty(){
    return head == tail;
}

bool isFull(){
    return head == (tail+1) % LEN;
}

void enqueue(P x){
    if(isFull()){
        fprintf(stderr, "オーバーフロー\n");
        exit(0);
    }
    Q[tail]=x;
    if(tail+1 == LEN){
        tail=0;
    }
    else{
        tail++;
    }
}

P dequeue(){
    P x;
    if(isEnpty()){
        fprintf(stderr, "アンダーフロー\n");
        exit(1);
    }
    x=Q[head];
    if(head+1 == LEN){
        head=0;
    }
    else{
        head++;
    }
    return x;
}
