#include <stdio.h>
#define N 100005

typedef struct NT
{
  char name[10];
  int time;
}nt;

void enqueue(nt x);
nt dequeue(void);

nt Q[N];
int head,tail,n;

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

  return 0;
}

void enqueue(nt x)
{
  Q[tail]=x;
  if (tail+1==N) tail=0;
  else tail++;
}

nt dequeue(void)
{
  nt x=Q[head];
  if(head+1==N) head=0;
  else head++;
  return x;
}