import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	static int[] numStack = new int[100];
	static int numOfs= 0;
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	}
	public static void strEnqueue(String str) {
		strList.add(str);
	}
	public static void intEnqueue(int num) {
		intList.add(num);
	}
	public static String strDequeue() {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	}
	public static int intDequeue() {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	}
	public static void numPush(int n) {
		numStack[numOfs++] = n;
	}
	public static int numPop() {
		return(Integer.valueOf(numStack[--numOfs]));
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	}
	public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int cardComp(String left, String right) {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util public class Main {
	static int[] numStack = new int[100];
	static int numOfs= 0;
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	}
	public static void strEnqueue(String str) {
		strList.add(str);
	}
	public static void intEnqueue(int num) {
		intList.add(num);
	}
	public static String strDequeue() {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	}
	public static int intDequeue() {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	}
	public static void numPush(int n) {
		numStack[numOfs++] = n;
	}
	public static int numPop() {
		return(Integer.valueOf(numStack[--numOfs]));
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	}
	public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int cardComp(String left, String right) {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} Main static int[] numStack = new int[100]; numStack new int[100] 100 static int numOfs= 0; numOfs 0 static ArrayList<String> strList = new ArrayList<String>(); strList new ArrayList<String>() static ArrayList<Integer> intList = new ArrayList<Integer>(); intList new ArrayList<Integer>() public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	} main {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	} BufferedReader breader = getReader(); breader getReader() getReader int[] elm = getIntAry(breader); elm getIntAry(breader) getIntAry breader int num = elm[0]; num elm[0] elm 0 int quantum = elm[1]; quantum elm[1] elm 1 for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		} int i = 0 ; int i = 0 ; i 0 i < num i num i++ i++ i {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		} {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		} String[] ps = getAry(breader); ps getAry(breader) getAry breader strEnqueue(ps[0]) strEnqueue ps[0] ps 0 intEnqueue(Integer.valueOf(ps[1])) intEnqueue Integer.valueOf(ps[1]) Integer.valueOf Integer ps[1] ps 1 String ps = strDequeue(); ps strDequeue() strDequeue int elapse = 0; elapse 0 while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		} ps != null ps null {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		} int ms = intDequeue(); ms intDequeue() intDequeue if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			} ms > quantum ms quantum {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} strEnqueue(ps) strEnqueue ps intEnqueue(ms-quantum) intEnqueue ms-quantum ms quantum elapse += quantum elapse quantum {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			} elapse += ms elapse ms System.out.println(ps + " " + elapse) System.out.println System.out System System.out ps + " " + elapse ps + " " + elapse ps " " elapse ps = strDequeue() ps strDequeue() strDequeue String[] args args public static void strEnqueue(String str) {
		strList.add(str);
	} strEnqueue {
		strList.add(str);
	} strList.add(str) strList.add strList str String str str public static void intEnqueue(int num) {
		intList.add(num);
	} intEnqueue {
		intList.add(num);
	} intList.add(num) intList.add intList num int num num public static String strDequeue() {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	} strDequeue {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	} String val; val if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		} strList.size() > 0 strList.size() strList.size strList 0 {
			val = strList.get(0);
			strList.remove(0);
		} val = strList.get(0) val strList.get(0) strList.get strList 0 strList.remove(0) strList.remove strList 0 {
			val = null;
		} val = null val null return val; val public static int intDequeue() {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	} intDequeue {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	} int val; val if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		} intList.size() > 0 intList.size() intList.size intList 0 {
			val = intList.get(0);
			intList.remove(0);
		} val = intList.get(0) val intList.get(0) intList.get intList 0 intList.remove(0) intList.remove intList 0 {
			val = -1;
		} val = -1 val -1 1 return val; val public static void numPush(int n) {
		numStack[numOfs++] = n;
	} numPush {
		numStack[numOfs++] = n;
	} numStack[numOfs++] = n numStack[numOfs++] numStack numOfs++ numOfs n int n n public static int numPop() {
		return(Integer.valueOf(numStack[--numOfs]));
	} numPop {
		return(Integer.valueOf(numStack[--numOfs]));
	} return(Integer.valueOf(numStack[--numOfs])); (Integer.valueOf(numStack[--numOfs])) Integer.valueOf Integer numStack[--numOfs] numStack --numOfs numOfs public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	} getReader {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	} return( new BufferedReader(new InputStreamReader(
				System.in))); ( new BufferedReader(new InputStreamReader(
				System.in))) public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	} getInt {
		String line = br.readLine();
		return Integer.valueOf(line);
	} String line = br.readLine(); line br.readLine() br.readLine br return Integer.valueOf(line); Integer.valueOf(line) Integer.valueOf Integer line BufferedReader br br public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	} getAry {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	} String line = br.readLine(); line br.readLine() br.readLine br String[] nstr = line.split(" "); nstr line.split(" ") line.split line " " return nstr; nstr BufferedReader br br public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	} getIntAry {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	} String line = br.readLine(); line br.readLine() br.readLine br String[] nstr = line.split(" "); nstr line.split(" ") line.split line " " int[] n = new int[nstr.length]; n new int[nstr.length] nstr.length nstr nstr.length for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		} int i=0 ; int i=0 ; i 0 i < nstr.length i nstr.length nstr nstr.length i++ i++ i {
			n[i] = Integer.valueOf(nstr[i]);
		} {
			n[i] = Integer.valueOf(nstr[i]);
		} n[i] = Integer.valueOf(nstr[i]) n[i] n i Integer.valueOf(nstr[i]) Integer.valueOf Integer nstr[i] nstr i return n; n BufferedReader br br public static int cardComp(String left, String right) {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	} cardComp {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	} char l = left.charAt(1); l left.charAt(1) left.charAt left 1 char r = right.charAt(1); r right.charAt(1) right.charAt right 1 return(l-r); (l-r) l r String left left String right right public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	} getAryMl {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	} int n = getInt(br); n getInt(br) getInt br int[] ary = new int[n]; ary new int[n] n for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		} int i=0 ; int i=0 ; i 0 i < n i n i++ i++ i {
			ary[i] = getInt(br);
		} {
			ary[i] = getInt(br);
		} ary[i] = getInt(br) ary[i] ary i getInt(br) getInt br return ary; ary BufferedReader br br public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	} putAry {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	} for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		} {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		} System.out.print(ary[i]) System.out.print System.out System System.out ary[i] ary i if ( i < num-1) {
				System.out.print(" ");
			} i < num-1 i num-1 num 1 {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.println("") System.out.println System.out System System.out "" int[] ary ary int num num public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	} putAry {
		putAry(ary, ary.length ) ;
	} putAry(ary, ary.length ) putAry ary ary.length ary ary.length int[] ary ary public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	} isPrime {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	} int r = (int)Math.sqrt((double)n)+1; r (int)Math.sqrt((double)n)+1 (int)Math.sqrt((double)n) Math.sqrt Math (double)n 1 for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		} int j = 2 ; int j = 2 ; j 2 j < r j r j += 1 j += 1 j 1 {
			if ( n%j == 0 ) {
				return false;
			}
		} {
			if ( n%j == 0 ) {
				return false;
			}
		} if ( n%j == 0 ) {
				return false;
			} n%j == 0 n%j n j 0 {
				return false;
			} return false; false return true; true int n n public class Main {
	static int[] numStack = new int[100];
	static int numOfs= 0;
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	}
	public static void strEnqueue(String str) {
		strList.add(str);
	}
	public static void intEnqueue(int num) {
		intList.add(num);
	}
	public static String strDequeue() {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	}
	public static int intDequeue() {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	}
	public static void numPush(int n) {
		numStack[numOfs++] = n;
	}
	public static int numPop() {
		return(Integer.valueOf(numStack[--numOfs]));
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	}
	public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int cardComp(String left, String right) {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} public class Main {
	static int[] numStack = new int[100];
	static int numOfs= 0;
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	}
	public static void strEnqueue(String str) {
		strList.add(str);
	}
	public static void intEnqueue(int num) {
		intList.add(num);
	}
	public static String strDequeue() {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	}
	public static int intDequeue() {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	}
	public static void numPush(int n) {
		numStack[numOfs++] = n;
	}
	public static int numPop() {
		return(Integer.valueOf(numStack[--numOfs]));
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	}
	public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int cardComp(String left, String right) {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	static int[] numStack = new int[100];
	static int numOfs= 0;
	static ArrayList<String> strList = new ArrayList<String>();
	static ArrayList<Integer> intList = new ArrayList<Integer>();

	public static void main(String[] args) throws Exception {
		BufferedReader breader = getReader();
		int[] elm = getIntAry(breader);
		int num = elm[0];
		int quantum = elm[1];
		for(int i = 0 ; i < num ; i++ ) {
			String[] ps = getAry(breader);
			strEnqueue(ps[0]);
			intEnqueue(Integer.valueOf(ps[1]));
		}
		String ps = strDequeue();
		int elapse = 0;
		while( ps != null) {
			int ms = intDequeue();
			if ( ms > quantum ) {
				strEnqueue(ps);
				intEnqueue(ms-quantum);
				elapse += quantum;
			} else {
				elapse += ms;
				System.out.println(ps + " " + elapse);
			}
			ps = strDequeue();
		}
	}
	public static void strEnqueue(String str) {
		strList.add(str);
	}
	public static void intEnqueue(int num) {
		intList.add(num);
	}
	public static String strDequeue() {
		String val;
		if ( strList.size() > 0 ) {
			val = strList.get(0);
			strList.remove(0);
		} else {
			val = null;
		}
		return val;
	}
	public static int intDequeue() {
		int val;
		if ( intList.size() > 0) {
			val = intList.get(0);
			intList.remove(0);
		} else {
			val = -1;
		}
		return val;
	}
	public static void numPush(int n) {
		numStack[numOfs++] = n;
	}
	public static int numPop() {
		return(Integer.valueOf(numStack[--numOfs]));
	}
	public static BufferedReader getReader() {
		return( new BufferedReader(new InputStreamReader(
				System.in)));
	}
	public static int getInt(BufferedReader br)throws Exception {
		String line = br.readLine();
		return Integer.valueOf(line);
	}
	public static String[] getAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		return nstr;
	}
	public static int[] getIntAry(BufferedReader br)throws Exception {
		String line = br.readLine();
		String[] nstr = line.split(" ");
		int[] n = new int[nstr.length];
		for( int i=0 ; i < nstr.length ; i++ ) {
			n[i] = Integer.valueOf(nstr[i]);
		}
		return n;
	}
	public static int cardComp(String left, String right) {
		char l = left.charAt(1);
		char r = right.charAt(1);
		return(l-r);
	}
	public static int[] getAryMl(BufferedReader br)throws Exception {
		int n = getInt(br);
		int[] ary = new int[n];
		for( int i=0 ; i < n ; i++ ) {
			ary[i] = getInt(br);
		}
		return ary;
	}
	public static void putAry(int[] ary, int num) {
		for( int i = 0; i < num ; i++ ) {
			System.out.print(ary[i]);
			if ( i < num-1) {
				System.out.print(" ");
			}
		}
		System.out.println("");
	}
	public static void putAry(int[] ary) {
		putAry(ary, ary.length ) ;
	}
	public static boolean isPrime(int n) {
		int r = (int)Math.sqrt((double)n)+1;
		for( int j = 2 ; j < r ; j += 1) {
			if ( n%j == 0 ) {
				return false;
			}
		}
		return true;
	}

}