#include <stdio.h>
#include <string.h>
#define N 100005
typedef struct a{
  char name[100];
  int t;
}A;

A Q[N];
int head=0,tail=0,n,cnt=0;

void enqueue(A x){
  Q[tail]=x;
  tail=(tail+1)%N;
}
A dequeue(){
  A x = Q[head];
  head = (head+1)%N;
  return x;
}
int minimum(int a,int b){
  if(a>b)return b;
  else return a;
}

int main() {
  A u;
  int elaps=0,c;
  int i,q;
  scanf("%d%d",&n,&q);
  for(int i=1;i<=n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    u=dequeue();
    c=minimum(q,u.t);
    u.t -= c;
    elaps  += c;
    if(u.t > 0)enqueue(u);
    else printf("%s %d\n",u.name,elaps);
  }
  return 0;
}

