#include<stdio.h>
#include<string.h>
#define MAX 100005

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

P Q[MAX];
int head, tail, n;

void enqueue(P u) {
Q[tail] = u;
tail = (tail + 1) % MAX;
}

P dequeue() {
P x = Q[head];
head = (head + 1) % MAX;
return x;
}

int min(int a, int b) { return a > b ? a : b; }

int main() {
int q, sum = 0 , w;
scanf("%d %d", &n,&q);

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

head = 1; tail = n + 1;
P u;
while (head != tail) {
u = dequeue();
w = min(q, u.t);
sum += w;
u.t -= w;
if (u.t > 0)enqueue(u);
else { printf("%s %d", u.name, sum); }
}
return 0;

}