#include<stdio.h>
#include<string.h>
#define int long long
typedef struct{
  char name[11];
  int time;
}data;
int head;
int tail;
signed main(){
  int n,q,i;
  data Q[100001];
  
  data ans[100001];
  int sum,j,cnt;
  int mod=100000;
  scanf("%lld%lld",&n,&q);
  head=0;
  tail=n;
  for(i=0;i<n;i++){
    scanf("%s%lld",Q[i].name,&Q[i].time);
  }
  sum=0;
  j=0;
  while(head!=tail){
    cnt=0;
    for(i=head;i<tail;i++){
      if(Q[i%mod].time<=q){
	ans[j]=Q[i%mod];
	ans[j].time+=sum;
	j++;
	sum+=Q[i%mod].time;
      }
      else{
	Q[(cnt+tail)%mod]=Q[i%mod];
	Q[(cnt+tail)%mod].time-=q;
	sum+=q;
	cnt++;
      }
    }
    head=tail;
    tail+=cnt;
	
  }
  for(i=0;i<n;i++){
    printf("%s %lld\n",ans[i].name,ans[i].time);
  }
  return 0;
}

