import java.util.*;
import java.io.*;
class Main{
    public static void main(String args[]) throws IOException {
	
	int i,j,n,q,time=0,a;
	String c;
	String array[] = new String[100000];
	Scanner scan = new Scanner(System.in);
	Queue<Integer> que = new ArrayDeque<Integer>();
	Queue<String> ques = new ArrayDeque<String>();
	
	n = 2*scan.nextInt();
	q = scan.nextInt();
	
	for(i=0;i<n;i++){
	    array[i] = scan.next();
	}
	for(i=0;i<n;i+=2){
	    c = array[i];
	   ques.add(c);
	}
	for(i=1;i<n;i+=2){
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	}
	
	i=1;
	while(true){
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	}
	
    }
}
 import java.util.*; util.* java import java.io.*; io.* java class Main{
    public static void main(String args[]) throws IOException {
	
	int i,j,n,q,time=0,a;
	String c;
	String array[] = new String[100000];
	Scanner scan = new Scanner(System.in);
	Queue<Integer> que = new ArrayDeque<Integer>();
	Queue<String> ques = new ArrayDeque<String>();
	
	n = 2*scan.nextInt();
	q = scan.nextInt();
	
	for(i=0;i<n;i++){
	    array[i] = scan.next();
	}
	for(i=0;i<n;i+=2){
	    c = array[i];
	   ques.add(c);
	}
	for(i=1;i<n;i+=2){
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	}
	
	i=1;
	while(true){
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	}
	
    }
} Main public static void main(String args[]) throws IOException {
	
	int i,j,n,q,time=0,a;
	String c;
	String array[] = new String[100000];
	Scanner scan = new Scanner(System.in);
	Queue<Integer> que = new ArrayDeque<Integer>();
	Queue<String> ques = new ArrayDeque<String>();
	
	n = 2*scan.nextInt();
	q = scan.nextInt();
	
	for(i=0;i<n;i++){
	    array[i] = scan.next();
	}
	for(i=0;i<n;i+=2){
	    c = array[i];
	   ques.add(c);
	}
	for(i=1;i<n;i+=2){
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	}
	
	i=1;
	while(true){
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	}
	
    } main {
	
	int i,j,n,q,time=0,a;
	String c;
	String array[] = new String[100000];
	Scanner scan = new Scanner(System.in);
	Queue<Integer> que = new ArrayDeque<Integer>();
	Queue<String> ques = new ArrayDeque<String>();
	
	n = 2*scan.nextInt();
	q = scan.nextInt();
	
	for(i=0;i<n;i++){
	    array[i] = scan.next();
	}
	for(i=0;i<n;i+=2){
	    c = array[i];
	   ques.add(c);
	}
	for(i=1;i<n;i+=2){
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	}
	
	i=1;
	while(true){
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	}
	
    } int i i j j n n q q time=0 time 0 a; a String c; c String array[] = new String[100000]; array new String[100000] 100000 Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Queue<Integer> que = new ArrayDeque<Integer>(); que new ArrayDeque<Integer>() Queue<String> ques = new ArrayDeque<String>(); ques new ArrayDeque<String>() n = 2*scan.nextInt() n 2*scan.nextInt() 2 scan.nextInt() scan.nextInt scan q = scan.nextInt() q scan.nextInt() scan.nextInt scan for(i=0;i<n;i++){
	    array[i] = scan.next();
	} i=0; i=0 i 0 i<n i n i++ i++ i {
	    array[i] = scan.next();
	} {
	    array[i] = scan.next();
	} array[i] = scan.next() array[i] array i scan.next() scan.next scan for(i=0;i<n;i+=2){
	    c = array[i];
	   ques.add(c);
	} i=0; i=0 i 0 i<n i n i+=2 i+=2 i 2 {
	    c = array[i];
	   ques.add(c);
	} {
	    c = array[i];
	   ques.add(c);
	} c = array[i] c array[i] array i ques.add(c) ques.add ques c for(i=1;i<n;i+=2){
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	} i=1; i=1 i 1 i<n i n i+=2 i+=2 i 2 {
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	} {
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	} a = Integer.parseInt(array[i]) a Integer.parseInt(array[i]) Integer.parseInt Integer array[i] array i que.add(a) que.add que a i=1 i 1 while(true){
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	} true {
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	} if(que.isEmpty()){break;} que.isEmpty() que.isEmpty que {break;} break; a = que.remove() a que.remove() que.remove que c = ques.remove() c ques.remove() ques.remove ques if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    } a-q<=0 a-q a q 0 {
		time += a;
		System.out.println(c+" "+time);
	    } time += a time a System.out.println(c+" "+time) System.out.println System.out System System.out c+" "+time c+" "+time c " " time {
		time += q;
		que.add(a-q);
		ques.add(c);
	    } time += q time q que.add(a-q) que.add que a-q a q ques.add(c) ques.add ques c String args[] args
import java.util.*;
import java.io.*;
class Main{
    public static void main(String args[]) throws IOException {
	
	int i,j,n,q,time=0,a;
	String c;
	String array[] = new String[100000];
	Scanner scan = new Scanner(System.in);
	Queue<Integer> que = new ArrayDeque<Integer>();
	Queue<String> ques = new ArrayDeque<String>();
	
	n = 2*scan.nextInt();
	q = scan.nextInt();
	
	for(i=0;i<n;i++){
	    array[i] = scan.next();
	}
	for(i=0;i<n;i+=2){
	    c = array[i];
	   ques.add(c);
	}
	for(i=1;i<n;i+=2){
	    a = Integer.parseInt(array[i]);
	    que.add(a);
	}
	
	i=1;
	while(true){
	    if(que.isEmpty()){break;}
	    //if(ques.isEmpty()){break;}
	    a = que.remove();
	    c = ques.remove();
	    if(a-q<=0){
		time += a;
		System.out.println(c+" "+time);
	    }
	    else {
		time += q;
		que.add(a-q);
		ques.add(c);
	    }
	}
	
    }
}

