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

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	}
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util import java.util.*; util.* java class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] fst = (br.readLine()).split(" "); fst (br.readLine()).split(" ") (br.readLine()).split (br.readLine()) br.readLine br " " int n = Integer.parseInt(fst[0]); n Integer.parseInt(fst[0]) Integer.parseInt Integer fst[0] fst 0 int quan = Integer.parseInt(fst[1]); quan Integer.parseInt(fst[1]) Integer.parseInt Integer fst[1] fst 1 int sumtime = 0; sumtime 0 Deque<Integer> stackint = new ArrayDeque<Integer>(); stackint new ArrayDeque<Integer>() Deque<String> stackst = new ArrayDeque<String>(); stackst new ArrayDeque<String>() for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		} int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		} {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		} String[] st = (br.readLine()).split(" "); st (br.readLine()).split(" ") (br.readLine()).split (br.readLine()) br.readLine br " " stackst.addLast(st[0]) stackst.addLast stackst st[0] st 0 stackint.addLast(Integer.parseInt(st[1])) stackint.addLast stackint Integer.parseInt(st[1]) Integer.parseInt Integer st[1] st 1 int a; a String b; b try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		} catch (NullPointerException e){
				// System.out.println("d");

		} NullPointerException e {
				// System.out.println("d");

		} {
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		} while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			} (a = stackint.pollFirst()) > 0 (a = stackint.pollFirst()) a stackint.pollFirst() stackint.pollFirst stackint 0 {
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			} b = stackst.pollFirst() b stackst.pollFirst() stackst.pollFirst stackst if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				} a <= quan a quan {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				} sumtime = sumtime + a sumtime sumtime + a sumtime a System.out.println(b + " " + sumtime) System.out.println System.out System System.out b + " " + sumtime b + " " + sumtime b " " sumtime {
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				} sumtime = sumtime + quan sumtime sumtime + quan sumtime quan a = a - quan a a - quan a quan stackint.addLast(a) stackint.addLast stackint a stackst.addLast(b) stackst.addLast stackst b String[] args args
import java.io.*;
import java.util.Arrays;
import java.util.*;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] fst = (br.readLine()).split(" ");
		int n = Integer.parseInt(fst[0]);
		int quan = Integer.parseInt(fst[1]);
		int sumtime = 0;
		Deque<Integer> stackint = new ArrayDeque<Integer>();
		Deque<String> stackst = new ArrayDeque<String>();
		for ( int i = 0; i<n ; i++ ) {
			String[] st = (br.readLine()).split(" ");
			stackst.addLast(st[0]);
			stackint.addLast(Integer.parseInt(st[1]));
		}
		int a;
		String b;
		try{
				// System.out.println("a");

			while((a = stackint.pollFirst()) > 0){
				b = stackst.pollFirst();
				if ( a <= quan) {
					sumtime = sumtime + a;
				// System.out.println("b");

					System.out.println(b + " " + sumtime);
				}else{
					sumtime = sumtime + quan;
					a = a - quan;
					stackint.addLast(a);
				// System.out.println("c");

					stackst.addLast(b);
				}
			}
		}catch (NullPointerException e){
				// System.out.println("d");

		}
	}
}