#include <stdio.h>

#define N 100000
typedef struct{
char name[10];
int time;
}process;

int isempty(void);
int isfull(void);
void enqueue(process);
process dequeue(void);


int head = 0, tail = 0,q;
process p[N];


int main(){
process x;
int i,n,t = 0;

scanf("%d%d",&n,&q);
for(i = 0; i < n; i++){
scanf("%s%d",x.name,&x.time);
enqueue(x);
}

while(head != tail){
if(p[head].time > q) {
p[head].time = p[head].time-q;
t += q;
enqueue(dequeue());
}

 else if(p[head].time <= q) {
t += p[head].time;
printf("%s %d\n",p[head].name,t);
dequeue();
}
}
return 0;
}


int isempty(){
return head == tail;
}

int isfull(){
return head == (tail + 1)%N;
}

void enqueue(process x){
/*if (isfull()){
ERROR();
exit(1);
}
*/
p[tail] = x;
if(tail + 1 == N-1) tail = 0;
 else tail++;
}

process dequeue(){
process x;

/*if(isempty()){
ERROR();
exit(1);
}
*/
x = p[head];
if(head + 1 == N-1) head = 0;
 else head++;
return x;
}