import java.util.Scanner;


public class Main {

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    }
}
 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    }
} Main public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    } main {
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int q = stdIn.nextInt(); q stdIn.nextInt() stdIn.nextInt stdIn String [] a = new String[n]; a new String[n] n int [] b = new int[n]; b new int[n] n String [] aa = new String[n]; aa new String[n] n int [] bb = new int[n]; bb new int[n] n for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        } {
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        } a[i] = stdIn.next() a[i] a i stdIn.next() stdIn.next stdIn b[i] = stdIn.nextInt() b[i] b i stdIn.nextInt() stdIn.nextInt stdIn stdIn.close() stdIn.close stdIn int index =0; index 0 int basictime=0; basictime 0 int ansIndex=0; ansIndex 0 while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        } true {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        } if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	} b[index]==0 b[index] b index 0 {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	} index++ index if(index==n){
            		//初期値へ
            		index=0;
            	} index==n index n {
            		//初期値へ
            		index=0;
            	} index=0 index 0 continue; int remaining =b[index]-q; remaining b[index]-q b[index] b index q if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	} remaining >0 remaining 0 {
        		b[index] = remaining;
        		basictime+= q;
        	} b[index] = remaining b[index] b index remaining basictime+= q basictime q {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	} b[index] = 0 b[index] b index 0 aa[ansIndex]=a[index] aa[ansIndex] aa ansIndex a[index] a index bb[ansIndex]=q + basictime + remaining bb[ansIndex] bb ansIndex q + basictime + remaining q + basictime + remaining q basictime remaining ansIndex++ ansIndex basictime+= q + remaining basictime q + remaining q remaining if(ansIndex==n){
        			break;
        		} ansIndex==n ansIndex n {
        			break;
        		} break; index++ index if(index==n){
        		//初期値へ
        		index=0;
        	} index==n index n {
        		//初期値へ
        		index=0;
        	} index=0 index 0 for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        } int i = 0; int i = 0; i 0 i < ansIndex i ansIndex i++ i++ i {
        	System.out.println(aa[i] + " " + bb[i]);
        } {
        	System.out.println(aa[i] + " " + bb[i]);
        } System.out.println(aa[i] + " " + bb[i]) System.out.println System.out System System.out aa[i] + " " + bb[i] aa[i] + " " + bb[i] aa[i] aa i " " bb[i] bb i String[] args args public class Main {

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    }
} public class Main {

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    }
} Main
import java.util.Scanner;


public class Main {

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    }
}

