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


class Main{
    public void run(){
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main{
    public void run(){
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
} Main public void run(){
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        }catch(Exception e){
            System.out.println(e);
        }
    } run {
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        }catch(Exception e){
            System.out.println(e);
        }
    } try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        }catch(Exception e){
            System.out.println(e);
        } catch(Exception e){
            System.out.println(e);
        } Exception e {
            System.out.println(e);
        } System.out.println(e) System.out.println System.out System System.out e {
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int count = 0; count 0 int n = 0 n 0 q = 0; q 0 String line; line Deque<String> name = new ArrayDeque<>(); name new ArrayDeque<>() Deque<Integer> time = new ArrayDeque<>(); time new ArrayDeque<>() String[] tmp; tmp int spentTime = 0; spentTime 0 while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            } (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            } if(Objects.equals(line,"")){
                    break;
                } Objects.equals(line,"") Objects.equals Objects line "" {
                    break;
                } break; tmp = line.split(" ") tmp line.split(" ") line.split line " " if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                } count == 0 count 0 {
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                } n = Integer.parseInt(tmp[0]) n Integer.parseInt(tmp[0]) Integer.parseInt Integer tmp[0] tmp 0 q = Integer.parseInt(tmp[1]) q Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 count++ count {
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                } name.addLast(tmp[0]) name.addLast name tmp[0] tmp 0 time.addLast(Integer.parseInt(tmp[1])) time.addLast time Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 String temp_name; temp_name int temp_time; temp_time while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            } name.size() != 0 name.size() name.size name 0 {
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            } temp_name = name.removeFirst() temp_name name.removeFirst() name.removeFirst name temp_time = time.removeFirst() temp_time time.removeFirst() time.removeFirst time if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                } temp_time > q temp_time q {
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                } temp_time -= q temp_time q name.addLast(temp_name) name.addLast name temp_name time.addLast(temp_time) time.addLast time temp_time spentTime += q spentTime q {
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                } System.out.println(temp_name + " " + (spentTime + temp_time)) System.out.println System.out System System.out temp_name + " " + (spentTime + temp_time) temp_name + " " + (spentTime + temp_time) temp_name " " (spentTime + temp_time) spentTime temp_time spentTime += temp_time spentTime temp_time public static void main(String[] args){
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args
import java.io.*;
import java.util.*;


class Main{
    public void run(){
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
            int count = 0;
            int n = 0,q = 0;
            String line;
            Deque<String> name = new ArrayDeque<>();
            Deque<Integer> time = new ArrayDeque<>();
            String[] tmp;
            int spentTime = 0;
            while((line = br.readLine()) != null){
                // System.out.println(line);
                if(Objects.equals(line,"")){
                    break;
                }
                tmp = line.split(" ");
                if(count == 0){
                    n = Integer.parseInt(tmp[0]);
                    q = Integer.parseInt(tmp[1]);
                    count++;
                }
                else{
                    name.addLast(tmp[0]);
                    time.addLast(Integer.parseInt(tmp[1]));
                }
            }

            String temp_name;
            int temp_time;
            while(name.size() != 0){
                temp_name = name.removeFirst();
                temp_time = time.removeFirst();

                if(temp_time > q){
                    temp_time -= q;
                    name.addLast(temp_name);
                    time.addLast(temp_time);
                    spentTime += q;
                }else{
                    System.out.println(temp_name + " " + (spentTime + temp_time));
                    spentTime += temp_time;
                }
            }
        }catch(Exception e){
            System.out.println(e);
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
}