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



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    }
   
}

class Myp{
    private String name;
    private int time;
    
    Myp(String n,int t){
        this.name= n;
        this.time = t;
    }

    Myp(){
        this("",0);
    }
    public String getname(){
        return this.name;
    }

    public int gettime(){
        return this.time;
    }

    public void settime(int t){
        this.time = t;
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    }
   
} Main public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str; str str = br.readLine() str br.readLine() br.readLine br String[] strs = str.split("\\s"); strs str.split("\\s") str.split str "\\s" int n = Integer.parseInt(strs[0]); n Integer.parseInt(strs[0]) Integer.parseInt Integer strs[0] strs 0 int q = Integer.parseInt(strs[1]); q Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 Queue<Myp> d = new ArrayDeque<Myp>(); d new ArrayDeque<Myp>() for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        } int i =0; int i =0; i 0 i<n i n i++ i++ i {
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        } {
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        } str = br.readLine() str br.readLine() br.readLine br String[] temp = str.split("\\s"); temp str.split("\\s") str.split str "\\s" d.offer(new Myp(temp[0],Integer.parseInt(temp[1]))) d.offer d new Myp(temp[0],Integer.parseInt(temp[1])) int endtime = 0; endtime 0 while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        } !d.isEmpty() d.isEmpty() d.isEmpty d {
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        } Myp p = d.poll(); p d.poll() d.poll d if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            } p.gettime() > q p.gettime() p.gettime p q {
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            } p.settime(p.gettime() - q) p.settime p p.gettime() - q p.gettime() p.gettime p q d.offer(p) d.offer d p endtime += q endtime q {
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            } endtime += p.gettime() endtime p.gettime() p.gettime p System.out.println(p.getname() + " " + endtime) System.out.println System.out System System.out p.getname() + " " + endtime p.getname() + " " + endtime p.getname() p.getname p " " endtime br.close() br.close br String[] args args class Myp{
    private String name;
    private int time;
    
    Myp(String n,int t){
        this.name= n;
        this.time = t;
    }

    Myp(){
        this("",0);
    }
    public String getname(){
        return this.name;
    }

    public int gettime(){
        return this.time;
    }

    public void settime(int t){
        this.time = t;
    }
} Myp private String name; name private int time; time Myp(String n,int t){
        this.name= n;
        this.time = t;
    } Myp {
        this.name= n;
        this.time = t;
    } this.name= n this.name this this.name n this.time = t this.time this this.time t String n n int t t Myp(){
        this("",0);
    } Myp {
        this("",0);
    } this("",0) this "" 0 public String getname(){
        return this.name;
    } getname {
        return this.name;
    } return this.name; this.name this this.name public int gettime(){
        return this.time;
    } gettime {
        return this.time;
    } return this.time; this.time this this.time public void settime(int t){
        this.time = t;
    } settime {
        this.time = t;
    } this.time = t this.time this this.time t int t t public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    }
   
} public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    }
   
} Main
import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;

        str = br.readLine();
        String[] strs = str.split("\\s");
        int n = Integer.parseInt(strs[0]);
        int q = Integer.parseInt(strs[1]);

        Queue<Myp> d = new ArrayDeque<Myp>();
        for(int i =0;i<n;i++){
            str = br.readLine();
            String[] temp = str.split("\\s");
            d.offer(new Myp(temp[0],Integer.parseInt(temp[1])));
        }
        
        int endtime = 0;
        while(!d.isEmpty()){
            Myp p = d.poll();
            if(p.gettime() > q){
                p.settime(p.gettime() - q);
                d.offer(p);
                endtime += q;
            }else{
                endtime += p.gettime();
                System.out.println(p.getname() + " " + endtime);
            }
        }

        br.close();
    }
   
}

class Myp{
    private String name;
    private int time;
    
    Myp(String n,int t){
        this.name= n;
        this.time = t;
    }

    Myp(){
        this("",0);
    }
    public String getname(){
        return this.name;
    }

    public int gettime(){
        return this.time;
    }

    public void settime(int t){
        this.time = t;
    }
}
