#include<stdio.h>
#include<string.h>

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

int main(){

  int i, n, q, cnt = 0, now = 0, tail, cumulative_cnt = 0;
  Data data[100000];
  
  scanf("%d%d",&n,&q);

  tail = n;

  for(i = 0; i < n; i++)scanf("%s%d",data[i].name,&data[i].time);

  while(1)
    {
      
      if(data[now].time < q)
	{
	  cumulative_cnt += data[now].time;
	  data[now].time = 0;
	}
      
      else
	{
	  cumulative_cnt += q;
	  data[now].time -= q;
	}
      
      if(data[now].time == 0)
	{
	  printf("%s %d\n",data[now].name, cumulative_cnt);

	  if(now == tail - 1)break;

	  now++;
	  
	  continue;
	}

      data[tail].time = data[now].time, strcpy(data[tail].name,data[now].name);

      now++, tail++;

      if(tail == 100000)tail = 0;
      if(now == 100000)now = 0;
      
    }

  return 0;
}
































/*
#include<stdio.h>
#include<string.h>

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

int main(){

  int i, n, q, cnt = 0, now = 0, cumulative_cnt = 0;
  Data data[100000];
  
  scanf("%d%d",&n,&q);

  for(i = 0; i < n; i++)scanf("%s%d",data[i].name,&data[i].time);

  while(1)
    {
      if(now == n - cnt)now = 0;
      if(cnt == n)break;
      if(data[now].time <= q && data[now].time > 0)
	{
	  cumulative_cnt += data[now].time;
	  printf("%s %d\n",data[now].name,cumulative_cnt);

	  cnt++;
	  
	  for(i = now; i < n - cnt; i++)
	    {
	      strcpy(data[i].name,data[i + 1].name);
	      data[i].time = data[i + 1].time; 
	    }
	  continue;
	}
      data[now].time -= q;
      cumulative_cnt += q;
      now++;
    }

  return 0;
}
*/

