import java.util.*;
import java.io.*;

class Main{
        static ArrayDeque<Elem> dq;
        static int size;
        static int max;
        static int time = 0;

        static class Elem{
                String s;
                Integer i;
                public Elem(String s, Integer i){
                        this.s = s;
                        this.i = i;
                }
                public int minus(int i){
                        int j = this.i>=i ? i : this.i;
                        this.i -= j;
                        return j;
                }
        }
        static void runqueue(){
                while(!dq.isEmpty()){
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                }
        }

        public static void main(String[] args) throws IOException{
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String[] line = br.readLine().split(" ");
                size = Integer.parseInt(line[0]);
                max = Integer.parseInt(line[1]);

                dq = new ArrayDeque<>();
                for(int i=0; i<size; i++){
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                }
                runqueue();
        }
} import java.util.*; util.* java import java.io.*; io.* java class Main{
        static ArrayDeque<Elem> dq;
        static int size;
        static int max;
        static int time = 0;

        static class Elem{
                String s;
                Integer i;
                public Elem(String s, Integer i){
                        this.s = s;
                        this.i = i;
                }
                public int minus(int i){
                        int j = this.i>=i ? i : this.i;
                        this.i -= j;
                        return j;
                }
        }
        static void runqueue(){
                while(!dq.isEmpty()){
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                }
        }

        public static void main(String[] args) throws IOException{
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String[] line = br.readLine().split(" ");
                size = Integer.parseInt(line[0]);
                max = Integer.parseInt(line[1]);

                dq = new ArrayDeque<>();
                for(int i=0; i<size; i++){
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                }
                runqueue();
        }
} Main static ArrayDeque<Elem> dq; dq static int size; size static int max; max static int time = 0; time 0 static void runqueue(){
                while(!dq.isEmpty()){
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                }
        } runqueue {
                while(!dq.isEmpty()){
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                }
        } while(!dq.isEmpty()){
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                } !dq.isEmpty() dq.isEmpty() dq.isEmpty dq {
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                } Elem e = dq.pollFirst(); e dq.pollFirst() dq.pollFirst dq time += e.minus(max) time e.minus(max) e.minus e max if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time); e.i>0 e.i e e.i 0 dq.offerLast(e) dq.offerLast dq e System.out.println(e.s + " " + time) System.out.println System.out System System.out e.s + " " + time e.s + " " + time e.s e e.s " " time public static void main(String[] args) throws IOException{
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String[] line = br.readLine().split(" ");
                size = Integer.parseInt(line[0]);
                max = Integer.parseInt(line[1]);

                dq = new ArrayDeque<>();
                for(int i=0; i<size; i++){
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                }
                runqueue();
        } main {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String[] line = br.readLine().split(" ");
                size = Integer.parseInt(line[0]);
                max = Integer.parseInt(line[1]);

                dq = new ArrayDeque<>();
                for(int i=0; i<size; i++){
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                }
                runqueue();
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " size = Integer.parseInt(line[0]) size Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 max = Integer.parseInt(line[1]) max Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 dq = new ArrayDeque<>() dq new ArrayDeque<>() for(int i=0; i<size; i++){
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                } int i=0; int i=0; i 0 i<size i size i++ i++ i {
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                } {
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                } line = br.readLine().split(" ") line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " Elem e = new Elem(line[0], Integer.parseInt(line[1])); e new Elem(line[0], Integer.parseInt(line[1])) dq.offerLast(e) dq.offerLast dq e runqueue() runqueue String[] args args static class Elem{
                String s;
                Integer i;
                public Elem(String s, Integer i){
                        this.s = s;
                        this.i = i;
                }
                public int minus(int i){
                        int j = this.i>=i ? i : this.i;
                        this.i -= j;
                        return j;
                }
        } Elem String s; s Integer i; i public Elem(String s, Integer i){
                        this.s = s;
                        this.i = i;
                } Elem {
                        this.s = s;
                        this.i = i;
                } this.s = s this.s this this.s s this.i = i this.i this this.i i String s s Integer i i public int minus(int i){
                        int j = this.i>=i ? i : this.i;
                        this.i -= j;
                        return j;
                } minus {
                        int j = this.i>=i ? i : this.i;
                        this.i -= j;
                        return j;
                } int j = this.i>=i ? i : this.i; j this.i>=i ? i : this.i this.i>=i this.i this this.i i i this.i this this.i this.i -= j this.i this this.i j return j; j int i i
import java.util.*;
import java.io.*;

class Main{
        static ArrayDeque<Elem> dq;
        static int size;
        static int max;
        static int time = 0;

        static class Elem{
                String s;
                Integer i;
                public Elem(String s, Integer i){
                        this.s = s;
                        this.i = i;
                }
                public int minus(int i){
                        int j = this.i>=i ? i : this.i;
                        this.i -= j;
                        return j;
                }
        }
        static void runqueue(){
                while(!dq.isEmpty()){
                        Elem e = dq.pollFirst();
                        time += e.minus(max);

                        if(e.i>0)
                                dq.offerLast(e);
                        else
                                System.out.println(e.s + " " + time);
                }
        }

        public static void main(String[] args) throws IOException{
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String[] line = br.readLine().split(" ");
                size = Integer.parseInt(line[0]);
                max = Integer.parseInt(line[1]);

                dq = new ArrayDeque<>();
                for(int i=0; i<size; i++){
                        line = br.readLine().split(" ");
                        Elem e = new Elem(line[0], Integer.parseInt(line[1]));
                        dq.offerLast(e);
                }
                runqueue();
        }
}