#include <stdio.h>
#include <string.h>
#define N 100000
#define Q 1000

struct que{
    char name[10];
    int time;
};

int main(){
    struct que in[N];
    char baf[10],baff[10];
    int c=0,i,x,y,z,n,q,t=0;

    scanf("%d%d",&n,&q);
    
    if(1<=n && n<=N && 1<=q && q<=Q){
        for(i=0 ; i<n ; i++){
            scanf("%s %d",&in[i].name,&in[i].time);
        }


        while(1){
            
            x = in[0].time - q;
            
            if(x > 0){ 
           
                if(n == 1){
                    in[0].time = x;
                    t += q;
                }
                else{
                strcpy(baff,in[n-1].name);
                z = in[n-1].time;
                    
                for(i=n-1 ; i>1 ; i--){           
                    strcpy(baf,in[i-1].name);
                    y = in[i-1].time;
                       strcpy(in[i-1].name,baff);
                       in[i-1].time = z;
                       strcpy(baff,baf);
                       z = y;                    
                }

                strcpy(in[n-1].name,in[0].name);
                in[n-1].time = x;
                strcpy(in[0].name,baf);
                in[0].time = y;
                t += q;
            //  for(i=0 ; i<n ; i++){
          // printf("%s %d\n",in[i].name,in[i].time);
      //  }

                }
            }
            else if(x <= 0){
                t += in[0].time;
                printf("%s %d\n",in[0].name,t);
                 
                strcpy(baff,in[n-1].name);
                z = in[n-1].time;
                 if(n!=1){
                for(i=n-1 ; i>0 ; i--){           
                    strcpy(baf,in[i-1].name);
                    y = in[i-1].time;
                    strcpy(in[i-1].name,baff);
                    in[i-1].time = z;
                    strcpy(baff,baf);
                    z = y;                    
                    }
                }

              n--;
                }
            if(n==0) break;
        }
    }
}

