#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;

int asort(const void *a, const void *b){
  int A = *(int *)a, B = *(int *)b;
  if(A > B) return  1;
  if(A < B) return -1;
  return 0;
}

int dsort(const void *a, const void *b){
  int A = *(int *)a, B = *(int *)b;
  if(A < B) return  1;
  if(A > B) return -1;
  return 0;
}

typedef struct {
  char name[20];
  int time;
} Process;

int
main(int argc, char *argv[])
{
  int n, q;
  scanf("%d %d", &n, &q);
  Process p[100000];
  rep(i, n) scanf("%s %d", p[i].name, &p[i].time);

  int que[1000000] = {};
  rep(i, n) que[i] = i;
  int f = 0; int t = n; int T = 0;
  while(f < t) {
    if(p[que[f]].time > q) {
      p[que[f]].time -= q;
      que[t] = que[f];
      f++; t++;
      T += q;
    } else {
      T += p[que[f]].time;
      printf("%s %d\n", p[que[f]].name, T);
      f++;
    }
  }
  
  return 0;
}
      
  
  
  

