#include<stdio.h>
#include<string.h>
#define N 100000
int min(int a, int b)
{return a < b ? a : b;}

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

data Q[N+1];
int head,tail,n;

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

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

int main(){
  int a=0,b,i,q;
  data data;
  scanf("%d%d", &n, &q);
  for(i = 1;i <= n; i++)
    scanf("%s%d", Q[i].name, &Q[i].t);

  head = 1;
  tail = n+1;

  while(1){
    if( head == tail) break;
    data = dequeue();
    b = min(q, data.t);
    data.t -= b;
    a += b;
    if(data.t > 0)
      enqueue(data);
    else
      printf("%s %d\n", data.name, a);
  }

  return 0;
}


