import java.util.Queue;
import java.util.*;

public class Main {
     public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     }
}
 import java.util.Queue; Queue java.util import java.util.*; util.* java public class Main {
     public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     }
} Main public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     } main {
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     } Scanner in = new Scanner(System.in); in new Scanner(System.in) Queue<String[]> input = new ArrayDeque<String[]>(); input new ArrayDeque<String[]>() int num = Integer.parseInt(in.next()) ; num Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int quan = Integer.parseInt(in.next()); quan Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            } int i=0; int i=0; i 0 i<num i num i++ i++ i {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            } {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            } String[] a = new String[2]; a new String[2] 2 a[0] = in.next() a[0] a 0 in.next() in.next in a[1] = in.next() a[1] a 1 in.next() in.next in input.add(a) input.add input a in.close() in.close in int calculate = 0; calculate 0 while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            } !input.isEmpty() input.isEmpty() input.isEmpty input {
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            } String[] k = input.remove(); k input.remove() input.remove input String name =(String) k[0]; name (String) k[0] k 0 int time =Integer.parseInt(k[1]); time Integer.parseInt(k[1]) Integer.parseInt Integer k[1] k 1 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 } time<=quan time quan {
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 } calculate=calculate+time calculate calculate+time calculate time System.out.println(name +" "+calculate) System.out.println System.out System System.out name +" "+calculate name +" "+calculate name " " calculate {
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 } k[1]=Integer.toString((time-quan)) k[1] k 1 Integer.toString((time-quan)) Integer.toString Integer (time-quan) time quan input.offer(k) input.offer input k calculate=calculate+quan calculate calculate+quan calculate quan String[] wjy wjy public class Main {
     public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     }
} public class Main {
     public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     }
} Main
import java.util.Queue;
import java.util.*;

public class Main {
     public static void main(String[] wjy){
            Scanner in = new Scanner(System.in);
            Queue<String[]> input = new ArrayDeque<String[]>();
            int num = Integer.parseInt(in.next()) ;
            int quan = Integer.parseInt(in.next());
            for (int i=0;i<num;i++) {
                String[] a = new String[2];
                a[0] = in.next();
                a[1] = in.next();
                input.add(a);
            }
            in.close();
            int calculate = 0;
            while (!input.isEmpty()){
                 String[] k = input.remove();
                 String name =(String) k[0];
                 int time =Integer.parseInt(k[1]);
                 if (time<=quan){
                    calculate=calculate+time;
                    System.out.println(name +" "+calculate);
                 }
                 else{
                    k[1]=Integer.toString((time-quan));
                    input.offer(k);
                    calculate=calculate+quan;
                 }
            }
     }
}

