import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String name[]=new String[n];
		
		String queue[]=new String[1000000];
		int head=0, tail=0;
		int totaltime=0;
		int now=0;
		Map<String,Integer> time=new HashMap<String,Integer>();
		
		for(int i=0;i<n;++i) {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		}

		while(now!=totaltime) {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		}
		

	}
}
 import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util import java.util.Stack; Stack java.util class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String name[]=new String[n];
		
		String queue[]=new String[1000000];
		int head=0, tail=0;
		int totaltime=0;
		int now=0;
		Map<String,Integer> time=new HashMap<String,Integer>();
		
		for(int i=0;i<n;++i) {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		}

		while(now!=totaltime) {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		}
		

	}
} Main public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String name[]=new String[n];
		
		String queue[]=new String[1000000];
		int head=0, tail=0;
		int totaltime=0;
		int now=0;
		Map<String,Integer> time=new HashMap<String,Integer>();
		
		for(int i=0;i<n;++i) {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		}

		while(now!=totaltime) {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		}
		

	} main {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String name[]=new String[n];
		
		String queue[]=new String[1000000];
		int head=0, tail=0;
		int totaltime=0;
		int now=0;
		Map<String,Integer> time=new HashMap<String,Integer>();
		
		for(int i=0;i<n;++i) {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		}

		while(now!=totaltime) {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		}
		

	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int q=sc.nextInt(); q sc.nextInt() sc.nextInt sc String name[]=new String[n]; name new String[n] n String queue[]=new String[1000000]; queue new String[1000000] 1000000 int head=0 head 0 tail=0; tail 0 int totaltime=0; totaltime 0 int now=0; now 0 Map<String,Integer> time=new HashMap<String,Integer>(); time new HashMap<String,Integer>() for(int i=0;i<n;++i) {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		} int i=0; int i=0; i 0 i<n i n ++i ++i i {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		} {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		} name[i]=sc.next() name[i] name i sc.next() sc.next sc time.put(name[i],sc.nextInt()) time.put time name[i] name i sc.nextInt() sc.nextInt sc totaltime+=time.get(name[i]) totaltime time.get(name[i]) time.get time name[i] name i queue[tail]=name[i] queue[tail] queue tail name[i] name i ++tail tail while(now!=totaltime) {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		} now!=totaltime now totaltime {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		} if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			} time.get(queue[head])>q time.get(queue[head]) time.get time queue[head] queue head q {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			} time.put(queue[head], time.get(queue[head])-q) time.put time queue[head] queue head time.get(queue[head])-q time.get(queue[head]) time.get time queue[head] queue head q queue[tail]=queue[head] queue[tail] queue tail queue[head] queue head ++head head ++tail tail now+=q now q {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			} now+=time.get(queue[head]) now time.get(queue[head]) time.get time queue[head] queue head System.out.println(queue[head]+" "+now) System.out.println System.out System System.out queue[head]+" "+now queue[head]+" "+now queue[head] queue head " " now ++head head String args[] args
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int q=sc.nextInt();
		String name[]=new String[n];
		
		String queue[]=new String[1000000];
		int head=0, tail=0;
		int totaltime=0;
		int now=0;
		Map<String,Integer> time=new HashMap<String,Integer>();
		
		for(int i=0;i<n;++i) {
			name[i]=sc.next();
			time.put(name[i],sc.nextInt());
			totaltime+=time.get(name[i]);
			queue[tail]=name[i];
			++tail;
		}

		while(now!=totaltime) {
			if(time.get(queue[head])>q) {
				time.put(queue[head], time.get(queue[head])-q);
				queue[tail]=queue[head];
				++head;
				++tail;
				now+=q;
			}
			else {
				now+=time.get(queue[head]);
				System.out.println(queue[head]+" "+now);
				++head;
			}
		}
		

	}
}

