import java.util.Scanner;
import java.util.ArrayList;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    }
    
}
class Process {
    String name;
    int time;
    Process (String name, int time) {
	this.name = name;
	this.time = time;
    }
} import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    }
    
} Main public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    } main {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String[] initial = scan.nextLine().split(" "); initial scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " int n = Integer.parseInt(initial[0]); n Integer.parseInt(initial[0]) Integer.parseInt Integer initial[0] initial 0 int q = Integer.parseInt(initial[1]); q Integer.parseInt(initial[1]) Integer.parseInt Integer initial[1] initial 1 ArrayList<Process> processes = new ArrayList<Process>(); processes new ArrayList<Process>() for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	} {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	} String[] input = scan.nextLine().split(" "); input scan.nextLine().split(" ") scan.nextLine().split scan.nextLine() scan.nextLine scan " " String name = input[0]; name input[0] input 0 int time = Integer.parseInt(input[1]); time Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 Process p = new Process(name, time); p new Process(name, time) processes.add(p) processes.add processes p int processTime = 0; processTime 0 while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	} !processes.isEmpty() processes.isEmpty() processes.isEmpty processes {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	} Process p = processes.remove(0); p processes.remove(0) processes.remove processes 0 if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    } p.time > q p.time p p.time q {
		processTime += q;
	    } processTime += q processTime q {
		processTime += p.time;
	    } processTime += p.time processTime p.time p p.time p.time = p.time - q p.time p p.time p.time - q p.time p p.time q if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    } p.time > 0 p.time p p.time 0 {
		processes.add(p);
	    } processes.add(p) processes.add processes p {
		System.out.println(p.name + " " + processTime);
	    } System.out.println(p.name + " " + processTime) System.out.println System.out System System.out p.name + " " + processTime p.name + " " + processTime p.name p p.name " " processTime 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) {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    }
    
} public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    }
    
} Main
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] initial = scan.nextLine().split(" ");
	int n = Integer.parseInt(initial[0]);
	int q = Integer.parseInt(initial[1]);
	ArrayList<Process> processes = new ArrayList<Process>();
	for (int i = 0; i < n; i++) {
	    String[] input = scan.nextLine().split(" ");
	    String name = input[0];
	    int time = Integer.parseInt(input[1]);
	    Process p = new Process(name, time);
	    processes.add(p);
	}
	
	int processTime = 0;
	while (!processes.isEmpty()) {
	    Process p = processes.remove(0);
	    if (p.time > q) {
		processTime += q;
	    } else {
		processTime += p.time;
	    }
	    p.time = p.time - q;
	    if (p.time > 0) {
		processes.add(p);
	    } else {
		System.out.println(p.name + " " + processTime);
	    }
	}
    }
    
}
class Process {
    String name;
    int time;
    Process (String name, int time) {
	this.name = name;
	this.time = time;
    }
}