import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final List<process> pl = new LinkedList<process>();
        String[] in = br.readLine().split(" ");
        final int n = Integer.parseInt(in[0]);
        final int q = Integer.parseInt(in[1]);
        int now = 0;
        for(int i = 0; i<n; i++){
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        }
        while(!pl.isEmpty()){
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        }
        out.flush();
    }
}

class process{
    private final String name;
    private int time;
    process(String name, int time){
        this.name = name;
        this.time = time;
    }
    public final String getName(){
        return name;
    }
    public final int getTime(){
        return time;
    }
    public final void setTime(int time){
        this.time = time;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Iterator; Iterator java.util import java.util.LinkedList; LinkedList java.util import java.util.List; List java.util class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final List<process> pl = new LinkedList<process>();
        String[] in = br.readLine().split(" ");
        final int n = Integer.parseInt(in[0]);
        final int q = Integer.parseInt(in[1]);
        int now = 0;
        for(int i = 0; i<n; i++){
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        }
        while(!pl.isEmpty()){
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        }
        out.flush();
    }
} Main public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final List<process> pl = new LinkedList<process>();
        String[] in = br.readLine().split(" ");
        final int n = Integer.parseInt(in[0]);
        final int q = Integer.parseInt(in[1]);
        int now = 0;
        for(int i = 0; i<n; i++){
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        }
        while(!pl.isEmpty()){
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        }
        out.flush();
    } main {
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final List<process> pl = new LinkedList<process>();
        String[] in = br.readLine().split(" ");
        final int n = Integer.parseInt(in[0]);
        final int q = Integer.parseInt(in[1]);
        int now = 0;
        for(int i = 0; i<n; i++){
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        }
        while(!pl.isEmpty()){
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        }
        out.flush();
    } final PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) final List<process> pl = new LinkedList<process>(); pl new LinkedList<process>() String[] in = br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " final int n = Integer.parseInt(in[0]); n Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 final int q = Integer.parseInt(in[1]); q Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 int now = 0; now 0 for(int i = 0; i<n; i++){
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        } {
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        } in = br.readLine().split(" ") in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " final String name = in[0]; name in[0] in 0 final int time = Integer.parseInt(in[1]); time Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            } time<=q time q {
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            } now += time now time out.print(name) out.print out name out.print(' ') out.print out ' ' out.println(now) out.println out now {
                now += q;
                pl.add(new process(name, time-q));
            } now += q now q pl.add(new process(name, time-q)) pl.add pl new process(name, time-q) while(!pl.isEmpty()){
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        } !pl.isEmpty() pl.isEmpty() pl.isEmpty pl {
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        } final Iterator<process> i = pl.iterator(); i pl.iterator() pl.iterator pl while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            } i.hasNext() i.hasNext i {
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            } final process p = i.next(); p i.next() i.next i if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                } p.getTime()<=q p.getTime() p.getTime p q {
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                } now += p.getTime() now p.getTime() p.getTime p out.print(p.getName()) out.print out p.getName() p.getName p out.print(' ') out.print out ' ' out.println(now) out.println out now i.remove() i.remove i {
                    now += q;
                    p.setTime(p.getTime()-q);
                } now += q now q p.setTime(p.getTime()-q) p.setTime p p.getTime()-q p.getTime() p.getTime p q out.flush() out.flush out String[] args args class process{
    private final String name;
    private int time;
    process(String name, int time){
        this.name = name;
        this.time = time;
    }
    public final String getName(){
        return name;
    }
    public final int getTime(){
        return time;
    }
    public final void setTime(int time){
        this.time = time;
    }
} process private final String name; name private int time; time process(String name, int time){
        this.name = name;
        this.time = time;
    } process {
        this.name = name;
        this.time = time;
    } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public final String getName(){
        return name;
    } getName {
        return name;
    } return name; name public final int getTime(){
        return time;
    } getTime {
        return time;
    } return time; time public final void setTime(int time){
        this.time = time;
    } setTime {
        this.time = time;
    } this.time = time this.time this this.time time int time time
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

class Main{
    public static void main(String[] args) throws IOException{
        final PrintWriter out = new PrintWriter(System.out);
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final List<process> pl = new LinkedList<process>();
        String[] in = br.readLine().split(" ");
        final int n = Integer.parseInt(in[0]);
        final int q = Integer.parseInt(in[1]);
        int now = 0;
        for(int i = 0; i<n; i++){
            in = br.readLine().split(" ");
            final String name = in[0];
            final int time = Integer.parseInt(in[1]);
            if(time<=q){
                now += time;
                out.print(name);
                out.print(' ');
                out.println(now);
            }else{
                now += q;
                pl.add(new process(name, time-q));
            }
        }
        while(!pl.isEmpty()){
            final Iterator<process> i = pl.iterator();
            while(i.hasNext()){
                final process p = i.next();
                if(p.getTime()<=q){
                    now += p.getTime();
                    out.print(p.getName());
                    out.print(' ');
                    out.println(now);
                    i.remove();
                }else{
                    now += q;
                    p.setTime(p.getTime()-q);
                }
            }
        }
        out.flush();
    }
}

class process{
    private final String name;
    private int time;
    process(String name, int time){
        this.name = name;
        this.time = time;
    }
    public final String getName(){
        return name;
    }
    public final int getTime(){
        return time;
    }
    public final void setTime(int time){
        this.time = time;
    }
}