import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayDeque;

public class Main{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] t = br.readLine().split(" ");
        int n = Integer.parseInt(t[0]);
        int q = Integer.parseInt(t[1]);
        ArrayDeque<P> Q = new ArrayDeque<P>();
        for(int i = 0; i < n; i++){
            t = br.readLine().split(" ");
            P p = new P();
            p.name = t[0];
            p.time = Integer.parseInt(t[1]);
            Q.addLast(p);
        }
        int sumTime = 0;
        StringBuilder sb = new StringBuilder();
        while(!Q.isEmpty()){
            P p = new P();
            p = Q.pollFirst();
            //p.time = p.time - q;                                                   
            if(p.time - q <= 0){
                sumTime += p.time;
                sb.append(p.name).append(" ").append(sumTime).append("\n");
            }else if(p.time - q > 0){
                p.time = p.time - q;
                Q.addLast(p);
                sumTime = sumTime + q;
            }
        }
        System.out.print(sb);
    }

}

class P{
    String name;
    int time;
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz