
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;


public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    }
}

class Process{
	String name;
	int time;

	Process(String name, int time){
		this.name = name;
		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.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    }
} Main public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br int num = Integer.parseInt(line.substring(0, line.indexOf(" "))); num Integer.parseInt(line.substring(0, line.indexOf(" "))) Integer.parseInt Integer line.substring(0, line.indexOf(" ")) line.substring line 0 line.indexOf(" ") line.indexOf line " " int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); q Integer.parseInt(line.substring(line.indexOf(" ") + 1)) Integer.parseInt Integer line.substring(line.indexOf(" ") + 1) line.substring line line.indexOf(" ") + 1 line.indexOf(" ") line.indexOf line " " 1 Deque<Process> deque = new ArrayDeque<Process>(); deque new ArrayDeque<Process>() for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        } {
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        } line = br.readLine() line br.readLine() br.readLine br String name = line.substring(0, line.indexOf(" ")); name line.substring(0, line.indexOf(" ")) line.substring line 0 line.indexOf(" ") line.indexOf line " " int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); time Integer.parseInt(line.substring(line.indexOf(" ") + 1)) Integer.parseInt Integer line.substring(line.indexOf(" ") + 1) line.substring line line.indexOf(" ") + 1 line.indexOf(" ") line.indexOf line " " 1 deque.addLast(new Process(name, time)) deque.addLast deque new Process(name, time) int maxTime = 0; maxTime 0 Deque<Process> resultDeque = new ArrayDeque<Process>(); resultDeque new ArrayDeque<Process>() while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        } !deque.isEmpty() deque.isEmpty() deque.isEmpty deque {
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        } Process p = deque.pollFirst(); p deque.pollFirst() deque.pollFirst deque if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	} p.time > q p.time p p.time q {
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	} p.time -= q p.time p p.time q maxTime += q maxTime q deque.addLast(p) deque.addLast deque p {
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	} maxTime += p.time maxTime p.time p p.time p.time = maxTime p.time p p.time maxTime resultDeque.addLast(p) resultDeque.addLast resultDeque p for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        } Process result resultDeque {
        	System.out.println(result.name + " " + result.time);
        } {
        	System.out.println(result.name + " " + result.time);
        } System.out.println(result.name + " " + result.time) System.out.println System.out System System.out result.name + " " + result.time result.name + " " + result.time result.name result result.name " " result.time result result.time String[] args args class Process{
	String name;
	int time;

	Process(String name, int time){
		this.name = name;
		this.time = time;
	}

} Process String name; name 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 class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    }
} public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    }
} Main

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;


public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int num = Integer.parseInt(line.substring(0, line.indexOf(" ")));
        int q = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        Deque<Process> deque = new ArrayDeque<Process>();

        for(int i = 0; i < num; i++){
        	line = br.readLine();
        	String name = line.substring(0, line.indexOf(" "));
        	int time = Integer.parseInt(line.substring(line.indexOf(" ") + 1));
        	deque.addLast(new Process(name, time));
        }

        int maxTime = 0;
        Deque<Process> resultDeque = new ArrayDeque<Process>();
        while(!deque.isEmpty()){
        	Process p = deque.pollFirst();
        	if(p.time > q){
        		p.time -= q;
        		maxTime += q;
        		deque.addLast(p);
        	}else{
        		maxTime += p.time;
        		p.time = maxTime;
        		resultDeque.addLast(p);
        	}
        }

        for(Process result: resultDeque){
        	System.out.println(result.name + " " + result.time);
        }


    }
}

class Process{
	String name;
	int time;

	Process(String name, int time){
		this.name = name;
		this.time = time;
	}

}
