#include<stdio.h>
#include<queue>
using namespace std;
struct Process
{
    char name[15];
    int time;
};
struct Process pro[100000];
int main()
{
    int n,q,t=0,sum=0,i=0;
    scanf("%d%d",&n,&q);
    queue<int> qu;
    queue<char*> p;
    while(t<n)
    {
        scanf("%s%d",pro[t].name,&pro[t].time);
        qu.push(pro[t].time);
        p.push(pro[t].name);
        t++;
    }
    while(i<n)
    {
        if(qu.empty()) break;
        else if(qu.front()>q)
        {
            sum += q;
            qu.push(qu.front()-q);
            qu.pop();
            p.push(p.front());
            p.pop();
        }
        else if(qu.front()<=q)
        {
            sum +=qu.front();
            printf("%s %d\n",p.front(),sum);
            p.pop();
            qu.pop();
            i++;
        }
    }
    return 0;
}
