import java.util.*;
import java.lang.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int work = Integer.parseInt(line[1]);
        int sumTime = 0;
        ArrayDeque<Struct> arr = new ArrayDeque<Struct>();
        for(int i = 0; i < n; i++){
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        }
        while(!(arr.isEmpty())){
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        }




    }
}
class Struct{
    String name;
    int time;
    public Struct(String n, int t){
        name = n;
        time = t;
    }
} import java.util.*; util.* java import java.lang.*; lang.* java class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int work = Integer.parseInt(line[1]);
        int sumTime = 0;
        ArrayDeque<Struct> arr = new ArrayDeque<Struct>();
        for(int i = 0; i < n; i++){
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        }
        while(!(arr.isEmpty())){
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        }




    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int work = Integer.parseInt(line[1]);
        int sumTime = 0;
        ArrayDeque<Struct> arr = new ArrayDeque<Struct>();
        for(int i = 0; i < n; i++){
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        }
        while(!(arr.isEmpty())){
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        }




    } main {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int work = Integer.parseInt(line[1]);
        int sumTime = 0;
        ArrayDeque<Struct> arr = new ArrayDeque<Struct>();
        for(int i = 0; i < n; i++){
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        }
        while(!(arr.isEmpty())){
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        }




    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String[] line = sc.nextLine().split(" "); line sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int n = Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int work = Integer.parseInt(line[1]); work Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 int sumTime = 0; sumTime 0 ArrayDeque<Struct> arr = new ArrayDeque<Struct>(); arr new ArrayDeque<Struct>() for(int i = 0; i < n; i++){
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        } {
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        } String[] line2 = sc.nextLine().split(" "); line2 sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " String name = line2[0]; name line2[0] line2 0 int time = Integer.parseInt(line2[1]); time Integer.parseInt(line2[1]) Integer.parseInt Integer line2[1] line2 1 Struct s = new Struct(name,time); s new Struct(name,time) arr.push(s) arr.push arr s while(!(arr.isEmpty())){
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        } !(arr.isEmpty()) (arr.isEmpty()) arr.isEmpty arr {
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        } Struct sb = arr.removeLast(); sb arr.removeLast() arr.removeLast arr if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            } sb.time > work sb.time sb sb.time work {
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            } sb.time-= work sb.time sb sb.time work arr.push(sb) arr.push arr sb sumTime+= work sumTime work {
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            } sumTime+=sb.time sumTime sb.time sb sb.time System.out.print(sb.name + " ") System.out.print System.out System System.out sb.name + " " sb.name sb sb.name " " System.out.println(sumTime) System.out.println System.out System System.out sumTime String args[] args class Struct{
    String name;
    int time;
    public Struct(String n, int t){
        name = n;
        time = t;
    }
} Struct String name; name int time; time public Struct(String n, int t){
        name = n;
        time = t;
    } Struct {
        name = n;
        time = t;
    } name = n name n time = t time t String n n int t t
import java.util.*;
import java.lang.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int work = Integer.parseInt(line[1]);
        int sumTime = 0;
        ArrayDeque<Struct> arr = new ArrayDeque<Struct>();
        for(int i = 0; i < n; i++){
            String[] line2 = sc.nextLine().split(" ");
            String name = line2[0];
            int time = Integer.parseInt(line2[1]);
            Struct s = new Struct(name,time);
            arr.push(s);
        }
        while(!(arr.isEmpty())){
            Struct sb = arr.removeLast();
            if(sb.time > work){
                sb.time-= work;
                arr.push(sb);
                sumTime+= work;
            }else{
                sumTime+=sb.time;
                System.out.print(sb.name + " ");
                System.out.println(sumTime);

            }

        }




    }
}
class Struct{
    String name;
    int time;
    public Struct(String n, int t){
        name = n;
        time = t;
    }
}