#include <stdio.h>
#include<string.h>
#define LEN 100001
   
typedef struct pp{
    char name[100];
    int t;
}P;

void printqueue(void);
   
P Q[LEN+1];
int head, tail , n;
   
void push(P x){
    Q[tail] = x;
    if(tail == n) tail = 0;
    else tail++;
}
   
P pop(){
    P res;
    res = Q[head];
    if(head == n) head = 0;
    else head++; 
    return res;
}
   
   
int main(){
    int time = 0, c = 0;
    int i, ms;
    P u;
    scanf("%d %d", &n, &ms);
   
    tail = n/2;   
    head = n/2;
   
    for ( i = 0; i <n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
   
    while(c != n){
   
        u = pop();
      
        if(u.t > ms) {
            time += ms;
            u.t -= ms;
            push(u);
        }

        else {
            time += u.t;
            printf("%s %d\n", u.name, time);
            c++;
        }
   
    }
  
    return 0;
}

void printqueue(void){
  int i;
   
  for(i=head; i!=tail; i++){
    if(i==n){
      printf("%s %d ",Q[i].name,Q[i].tim);
      i=0;
      printf("\n");
    }
    printf("%s %d ",Q[i].name,Q[i].tim);
    printf("\n");
  }
 
}