/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String[] str = s.split(" ");
		long count = 0;
		long timer = 0;
		int time = 0;
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		String name = new String();
		int[] array = new int[n];
		Queue<Integer> queue = new LinkedList<Integer>();
		Queue<String> namequeue = new LinkedList<String>();
		for(int i=0;i<n;i++){
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		}
		for(int i=0;queue.isEmpty()!=true;i++){
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		}
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.lang.reflect.Array; Array java.lang.reflect import java.io.*; io.* java class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String[] str = s.split(" ");
		long count = 0;
		long timer = 0;
		int time = 0;
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		String name = new String();
		int[] array = new int[n];
		Queue<Integer> queue = new LinkedList<Integer>();
		Queue<String> namequeue = new LinkedList<String>();
		for(int i=0;i<n;i++){
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		}
		for(int i=0;queue.isEmpty()!=true;i++){
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		}
	}
} Main public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String[] str = s.split(" ");
		long count = 0;
		long timer = 0;
		int time = 0;
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		String name = new String();
		int[] array = new int[n];
		Queue<Integer> queue = new LinkedList<Integer>();
		Queue<String> namequeue = new LinkedList<String>();
		for(int i=0;i<n;i++){
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		}
		for(int i=0;queue.isEmpty()!=true;i++){
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String[] str = s.split(" ");
		long count = 0;
		long timer = 0;
		int time = 0;
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		String name = new String();
		int[] array = new int[n];
		Queue<Integer> queue = new LinkedList<Integer>();
		Queue<String> namequeue = new LinkedList<String>();
		for(int i=0;i<n;i++){
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		}
		for(int i=0;queue.isEmpty()!=true;i++){
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String s=br.readLine(); s br.readLine() br.readLine br String[] str = s.split(" "); str s.split(" ") s.split s " " long count = 0; count 0 long timer = 0; timer 0 int time = 0; time 0 int n = Integer.parseInt(str[0]); n Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int q = Integer.parseInt(str[1]); q Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 String name = new String(); name new String() int[] array = new int[n]; array new int[n] n Queue<Integer> queue = new LinkedList<Integer>(); queue new LinkedList<Integer>() Queue<String> namequeue = new LinkedList<String>(); namequeue new LinkedList<String>() for(int i=0;i<n;i++){
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		} {
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		} s = br.readLine() s br.readLine() br.readLine br str = s.split(" ") str s.split(" ") s.split s " " namequeue.add(str[0]) namequeue.add namequeue str[0] str 0 queue.add(Integer.parseInt(str[1])) queue.add queue Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 for(int i=0;queue.isEmpty()!=true;i++){
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		} int i=0; int i=0; i 0 queue.isEmpty()!=true queue.isEmpty() queue.isEmpty queue true i++ i++ i {
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		} {
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		} time=queue.poll() time queue.poll() queue.poll queue name=namequeue.poll() name namequeue.poll() namequeue.poll namequeue if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			} time>q time q {
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			} queue.add(time-q) queue.add queue time-q time q namequeue.add(name) namequeue.add namequeue name timer+=q timer q {
				timer+=time;
				System.out.println(name+" "+timer);
			} timer+=time timer time System.out.println(name+" "+timer) System.out.println System.out System System.out name+" "+timer name+" "+timer name " " timer String[] args args
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.lang.reflect.Array;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s=br.readLine();
		String[] str = s.split(" ");
		long count = 0;
		long timer = 0;
		int time = 0;
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);
		String name = new String();
		int[] array = new int[n];
		Queue<Integer> queue = new LinkedList<Integer>();
		Queue<String> namequeue = new LinkedList<String>();
		for(int i=0;i<n;i++){
			s = br.readLine();
			str = s.split(" ");
			namequeue.add(str[0]);
			queue.add(Integer.parseInt(str[1]));
		}
		for(int i=0;queue.isEmpty()!=true;i++){
			time=queue.poll();
			name=namequeue.poll();
			if(time>q){
				queue.add(time-q);
				namequeue.add(name);
				timer+=q;
			}
			else{
				timer+=time;
				System.out.println(name+" "+timer);
			}
		}
	}
}