import java.io.*;
class Que {
   int queStart;
   int queTail;
   int procTime;
   String[] arry;
   int elapsedTime;
   int max;
    public Que(int procTime,  int maxLen) {
        this.queStart = 0;
        this.queTail = 0;
        this.procTime = procTime;
        this.elapsedTime = 0;
        this.arry = new String[maxLen+1];
        this.max = maxLen+1;
    }
    public boolean isEmpty() {
        return queStart == queTail;
    }
    public boolean isFull() {
        return queStart == (queTail+1) % max;
    }
    public void enqueue (String arg){
        if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        }
    }
    public String dequeue() {
        if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        }
    }
    public void eval(Que que){
        String[]ary = que.dequeue().split(" ");
        String val = ary[0];
        int necessTime = Integer.parseInt(ary[1]);
        if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        }
    }
}

class Main {
    public static void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] init = br.readLine().split(" ");
        int count = Integer.valueOf(init[0]);
        int procTime = Integer.valueOf(init[1]);
       
        int elapsedTime = 0;
        Que que = new Que(procTime, count);
        for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        }
        while(!que.isEmpty()){
            que.eval(que);
        }
    }
}
        
 import java.io.*; io.* java class Que {
   int queStart;
   int queTail;
   int procTime;
   String[] arry;
   int elapsedTime;
   int max;
    public Que(int procTime,  int maxLen) {
        this.queStart = 0;
        this.queTail = 0;
        this.procTime = procTime;
        this.elapsedTime = 0;
        this.arry = new String[maxLen+1];
        this.max = maxLen+1;
    }
    public boolean isEmpty() {
        return queStart == queTail;
    }
    public boolean isFull() {
        return queStart == (queTail+1) % max;
    }
    public void enqueue (String arg){
        if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        }
    }
    public String dequeue() {
        if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        }
    }
    public void eval(Que que){
        String[]ary = que.dequeue().split(" ");
        String val = ary[0];
        int necessTime = Integer.parseInt(ary[1]);
        if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        }
    }
} Que int queStart; queStart int queTail; queTail int procTime; procTime String[] arry; arry int elapsedTime; elapsedTime int max; max public Que(int procTime,  int maxLen) {
        this.queStart = 0;
        this.queTail = 0;
        this.procTime = procTime;
        this.elapsedTime = 0;
        this.arry = new String[maxLen+1];
        this.max = maxLen+1;
    } Que {
        this.queStart = 0;
        this.queTail = 0;
        this.procTime = procTime;
        this.elapsedTime = 0;
        this.arry = new String[maxLen+1];
        this.max = maxLen+1;
    } this.queStart = 0 this.queStart this this.queStart 0 this.queTail = 0 this.queTail this this.queTail 0 this.procTime = procTime this.procTime this this.procTime procTime this.elapsedTime = 0 this.elapsedTime this this.elapsedTime 0 this.arry = new String[maxLen+1] this.arry this this.arry new String[maxLen+1] maxLen+1 maxLen 1 this.max = maxLen+1 this.max this this.max maxLen+1 maxLen 1 int procTime procTime int maxLen maxLen public boolean isEmpty() {
        return queStart == queTail;
    } isEmpty {
        return queStart == queTail;
    } return queStart == queTail; queStart == queTail queStart queTail public boolean isFull() {
        return queStart == (queTail+1) % max;
    } isFull {
        return queStart == (queTail+1) % max;
    } return queStart == (queTail+1) % max; queStart == (queTail+1) % max queStart (queTail+1) % max (queTail+1) queTail 1 max public void enqueue (String arg){
        if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        }
    } enqueue {
        if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        }
    } if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        } !(isFull()) (isFull()) isFull {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } arry[queTail] = arg arry[queTail] arry queTail arg queTail++ queTail queTail %= max queTail max {
            System.out.println("full");
        } System.out.println("full") System.out.println System.out System System.out "full" String arg arg public String dequeue() {
        if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        }
    } dequeue {
        if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        }
    } if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        } !isEmpty() isEmpty() isEmpty {
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } int now = queStart; now queStart queStart++ queStart queStart %= max queStart max return arry[now]; arry[now] arry now {
            System.out.println("empty");
            return null;
        } System.out.println("empty") System.out.println System.out System System.out "empty" return null; null public void eval(Que que){
        String[]ary = que.dequeue().split(" ");
        String val = ary[0];
        int necessTime = Integer.parseInt(ary[1]);
        if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        }
    } eval {
        String[]ary = que.dequeue().split(" ");
        String val = ary[0];
        int necessTime = Integer.parseInt(ary[1]);
        if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        }
    } String[]ary = que.dequeue().split(" "); ary que.dequeue().split(" ") que.dequeue().split que.dequeue() que.dequeue que " " String val = ary[0]; val ary[0] ary 0 int necessTime = Integer.parseInt(ary[1]); necessTime Integer.parseInt(ary[1]) Integer.parseInt Integer ary[1] ary 1 if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        } necessTime > procTime necessTime procTime {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } elapsedTime += procTime elapsedTime procTime que.enqueue(val+ " " + (necessTime-procTime)) que.enqueue que val+ " " + (necessTime-procTime) val+ " " + (necessTime-procTime) val " " (necessTime-procTime) necessTime procTime {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        } elapsedTime += necessTime elapsedTime necessTime System.out.println(val + " " + elapsedTime) System.out.println System.out System System.out val + " " + elapsedTime val + " " + elapsedTime val " " elapsedTime Que que que class Main {
    public static void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] init = br.readLine().split(" ");
        int count = Integer.valueOf(init[0]);
        int procTime = Integer.valueOf(init[1]);
       
        int elapsedTime = 0;
        Que que = new Que(procTime, count);
        for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        }
        while(!que.isEmpty()){
            que.eval(que);
        }
    }
} Main public static void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] init = br.readLine().split(" ");
        int count = Integer.valueOf(init[0]);
        int procTime = Integer.valueOf(init[1]);
       
        int elapsedTime = 0;
        Que que = new Que(procTime, count);
        for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        }
        while(!que.isEmpty()){
            que.eval(que);
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] init = br.readLine().split(" ");
        int count = Integer.valueOf(init[0]);
        int procTime = Integer.valueOf(init[1]);
       
        int elapsedTime = 0;
        Que que = new Que(procTime, count);
        for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        }
        while(!que.isEmpty()){
            que.eval(que);
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String [] init = br.readLine().split(" "); init br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int count = Integer.valueOf(init[0]); count Integer.valueOf(init[0]) Integer.valueOf Integer init[0] init 0 int procTime = Integer.valueOf(init[1]); procTime Integer.valueOf(init[1]) Integer.valueOf Integer init[1] init 1 int elapsedTime = 0; elapsedTime 0 Que que = new Que(procTime, count); que new Que(procTime, count) for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        } int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
            que.enqueue(br.readLine());
        } {
            que.enqueue(br.readLine());
        } que.enqueue(br.readLine()) que.enqueue que br.readLine() br.readLine br while(!que.isEmpty()){
            que.eval(que);
        } !que.isEmpty() que.isEmpty() que.isEmpty que {
            que.eval(que);
        } que.eval(que) que.eval que que String...args args
import java.io.*;
class Que {
   int queStart;
   int queTail;
   int procTime;
   String[] arry;
   int elapsedTime;
   int max;
    public Que(int procTime,  int maxLen) {
        this.queStart = 0;
        this.queTail = 0;
        this.procTime = procTime;
        this.elapsedTime = 0;
        this.arry = new String[maxLen+1];
        this.max = maxLen+1;
    }
    public boolean isEmpty() {
        return queStart == queTail;
    }
    public boolean isFull() {
        return queStart == (queTail+1) % max;
    }
    public void enqueue (String arg){
        if(!(isFull())) {
            arry[queTail] = arg;
            queTail++;
            queTail %= max;
        } else {
            System.out.println("full");
        }
    }
    public String dequeue() {
        if(!isEmpty()){
            int now = queStart;
            queStart++;
            queStart %= max;
            return arry[now];
        } else {
            System.out.println("empty");
            return null;
        }
    }
    public void eval(Que que){
        String[]ary = que.dequeue().split(" ");
        String val = ary[0];
        int necessTime = Integer.parseInt(ary[1]);
        if(necessTime > procTime) {
            elapsedTime += procTime;
            que.enqueue(val+ " " + (necessTime-procTime));
        } else {
            elapsedTime += necessTime;
            System.out.println(val + " " + elapsedTime);
        }
    }
}

class Main {
    public static void main(String...args)throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String [] init = br.readLine().split(" ");
        int count = Integer.valueOf(init[0]);
        int procTime = Integer.valueOf(init[1]);
       
        int elapsedTime = 0;
        Que que = new Que(procTime, count);
        for(int i = 0; i < count; i++) {
            que.enqueue(br.readLine());
        }
        while(!que.isEmpty()){
            que.eval(que);
        }
    }
}
        

