import java.util.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	}
	
	
	
	static class Process{
		String name; int time;
		public Process(String s, int t){
			name = s; time = t;
		}
		public void setName(String nm){
			name = nm;
		}
		public String getName(){
			return name;
		}
		public void setTime(int t){
			time = t;
		}
		public int getTime(){
			return time;
		}
	}

} import java.util.*; util.* java public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	}
	
	
	
	static class Process{
		String name; int time;
		public Process(String s, int t){
			name = s; time = t;
		}
		public void setName(String nm){
			name = nm;
		}
		public String getName(){
			return name;
		}
		public void setTime(int t){
			time = t;
		}
		public int getTime(){
			return time;
		}
	}

} Main final static int MOD = 1000000007; MOD 1000000007 final static int INF = 1000000000; INF 1000000000 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Queue<Process> que = new ArrayDeque<Process>(); que new ArrayDeque<Process>() int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int q = Integer.parseInt(sc.next()); q Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		} {
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		} String nm = sc.next(); nm sc.next() sc.next sc int t = Integer.parseInt(sc.next()); t Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc que.add(new Process(nm, t)) que.add que new Process(nm, t) sc.close() sc.close sc int t = 0; t 0 while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		} !que.isEmpty() que.isEmpty() que.isEmpty que {
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		} Process cur = que.poll(); cur que.poll() que.poll que int prctime = Math.min(q, cur.getTime()); prctime Math.min(q, cur.getTime()) Math.min Math q cur.getTime() cur.getTime cur cur.setTime(cur.getTime() - prctime) cur.setTime cur cur.getTime() - prctime cur.getTime() cur.getTime cur prctime t += prctime t prctime if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t); cur.getTime() > 0 cur.getTime() cur.getTime cur 0 que.add(cur) que.add que cur System.out.printf("%s %d\n", cur.getName(), t) System.out.printf System.out System System.out "%s %d\n" cur.getName() cur.getName cur t String[] args args static class Process{
		String name; int time;
		public Process(String s, int t){
			name = s; time = t;
		}
		public void setName(String nm){
			name = nm;
		}
		public String getName(){
			return name;
		}
		public void setTime(int t){
			time = t;
		}
		public int getTime(){
			return time;
		}
	} Process String name; name int time; time public Process(String s, int t){
			name = s; time = t;
		} Process {
			name = s; time = t;
		} name = s name s time = t time t String s s int t t public void setName(String nm){
			name = nm;
		} setName {
			name = nm;
		} name = nm name nm String nm nm public String getName(){
			return name;
		} getName {
			return name;
		} return name; name public void setTime(int t){
			time = t;
		} setTime {
			time = t;
		} time = t time t int t t public int getTime(){
			return time;
		} getTime {
			return time;
		} return time; time public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	}
	
	
	
	static class Process{
		String name; int time;
		public Process(String s, int t){
			name = s; time = t;
		}
		public void setName(String nm){
			name = nm;
		}
		public String getName(){
			return name;
		}
		public void setTime(int t){
			time = t;
		}
		public int getTime(){
			return time;
		}
	}

} public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	}
	
	
	
	static class Process{
		String name; int time;
		public Process(String s, int t){
			name = s; time = t;
		}
		public void setName(String nm){
			name = nm;
		}
		public String getName(){
			return name;
		}
		public void setTime(int t){
			time = t;
		}
		public int getTime(){
			return time;
		}
	}

} Main
import java.util.*;

public class Main{
	final static int MOD = 1000000007;
	final static int INF = 1000000000;

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Queue<Process> que = new ArrayDeque<Process>();
		int n = Integer.parseInt(sc.next());
		int q = Integer.parseInt(sc.next());
		for(int i = 0; i < n; ++i){
			String nm = sc.next();
			int t = Integer.parseInt(sc.next());
			que.add(new Process(nm, t));
		}
		sc.close();
		int t = 0;
		while(!que.isEmpty()){
			Process cur = que.poll();
			int prctime = Math.min(q, cur.getTime());
			cur.setTime(cur.getTime() - prctime);
			t += prctime;
			if(cur.getTime() > 0)
				que.add(cur);
			else System.out.printf("%s %d\n", cur.getName(), t);
		}
	}
	
	
	
	static class Process{
		String name; int time;
		public Process(String s, int t){
			name = s; time = t;
		}
		public void setName(String nm){
			name = nm;
		}
		public String getName(){
			return name;
		}
		public void setTime(int t){
			time = t;
		}
		public int getTime(){
			return time;
		}
	}

}
