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

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

	line = br.readLine();
	int n = Integer.parseInt(line.substring(0,line.indexOf(' ')));
	int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	Deque<Process> queue = new ArrayDeque<Process>();
	
	for(int i = 0;i < n;i++){
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	}
	int elapse = 0;
	StringBuilder sb = new StringBuilder();
	while (!queue.isEmpty()) {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	}
	System.out.print(sb);
    }
}
class Process{
    private String name;
    private int time;
    public Process(String name,int time){
	this.name = name;
	this.time = time;
    }
    public void setName(String name){
	this.name = name;
    }
    public String getName(){
	return this.name;
    }
    public void setTime(int time){
	this.time = time;
    }
    public int getTime(){
	return this.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 class Main{
    public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;

	line = br.readLine();
	int n = Integer.parseInt(line.substring(0,line.indexOf(' ')));
	int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	Deque<Process> queue = new ArrayDeque<Process>();
	
	for(int i = 0;i < n;i++){
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	}
	int elapse = 0;
	StringBuilder sb = new StringBuilder();
	while (!queue.isEmpty()) {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	}
	System.out.print(sb);
    }
} Main public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;

	line = br.readLine();
	int n = Integer.parseInt(line.substring(0,line.indexOf(' ')));
	int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	Deque<Process> queue = new ArrayDeque<Process>();
	
	for(int i = 0;i < n;i++){
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	}
	int elapse = 0;
	StringBuilder sb = new StringBuilder();
	while (!queue.isEmpty()) {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	}
	System.out.print(sb);
    } main {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String line;

	line = br.readLine();
	int n = Integer.parseInt(line.substring(0,line.indexOf(' ')));
	int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	Deque<Process> queue = new ArrayDeque<Process>();
	
	for(int i = 0;i < n;i++){
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	}
	int elapse = 0;
	StringBuilder sb = new StringBuilder();
	while (!queue.isEmpty()) {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	}
	System.out.print(sb);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line; line line = br.readLine() line br.readLine() br.readLine br int n = Integer.parseInt(line.substring(0,line.indexOf(' '))); n 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> queue = new ArrayDeque<Process>(); queue new ArrayDeque<Process>() for(int i = 0;i < n;i++){
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	} {
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(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 queue.offer(new Process(name,time)) queue.offer queue new Process(name,time) int elapse = 0; elapse 0 StringBuilder sb = new StringBuilder(); sb new StringBuilder() while (!queue.isEmpty()) {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	} !queue.isEmpty() queue.isEmpty() queue.isEmpty queue {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	} Process p = queue.poll(); p queue.poll() queue.poll queue if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    } p.getTime() <= q p.getTime() p.getTime p q {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } elapse += p.getTime() elapse p.getTime() p.getTime p sb.append(p.getName() + " " + elapse + "\n") sb.append sb p.getName() + " " + elapse + "\n" elapse p.getName() + " " + elapse + "\n" p.getName() p.getName p " " elapse "\n" {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    } p.setTime(p.getTime() - q) p.setTime p p.getTime() - q p.getTime() p.getTime p q elapse += q elapse q queue.offer(p) queue.offer queue p System.out.print(sb) System.out.print System.out System System.out sb String[] args args class Process{
    private String name;
    private int time;
    public Process(String name,int time){
	this.name = name;
	this.time = time;
    }
    public void setName(String name){
	this.name = name;
    }
    public String getName(){
	return this.name;
    }
    public void setTime(int time){
	this.time = time;
    }
    public int getTime(){
	return this.time; 
    }
} Process private String name; name private int time; time public 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 void setName(String name){
	this.name = name;
    } setName {
	this.name = name;
    } this.name = name this.name this this.name name String name name public String getName(){
	return this.name;
    } getName {
	return this.name;
    } return this.name; this.name this this.name public void setTime(int time){
	this.time = time;
    } setTime {
	this.time = time;
    } this.time = time this.time this this.time time int time time public int getTime(){
	return this.time; 
    } getTime {
	return this.time; 
    } return this.time; this.time this this.time
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

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

	line = br.readLine();
	int n = Integer.parseInt(line.substring(0,line.indexOf(' ')));
	int q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	Deque<Process> queue = new ArrayDeque<Process>();
	
	for(int i = 0;i < n;i++){
	    line = br.readLine();
	    String name = line.substring(0,line.indexOf(' '));
	    int time = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
	    queue.offer(new Process(name,time));
	}
	int elapse = 0;
	StringBuilder sb = new StringBuilder();
	while (!queue.isEmpty()) {
	    Process p = queue.poll();
	    if (p.getTime() <= q) {
		elapse += p.getTime();
		sb.append(p.getName() + " " + elapse + "\n");
	    } else {
		p.setTime(p.getTime() - q);
		elapse += q;
		queue.offer(p);
	    }
	}
	System.out.print(sb);
    }
}
class Process{
    private String name;
    private int time;
    public Process(String name,int time){
	this.name = name;
	this.time = time;
    }
    public void setName(String name){
	this.name = name;
    }
    public String getName(){
	return this.name;
    }
    public void setTime(int time){
	this.time = time;
    }
    public int getTime(){
	return this.time; 
    }
}
      

