import java.util.List;
import java.util.ArrayList;

import java.util.Scanner;
class Main{
    static public void  main(String[] av){
        int sum=0;

        Scanner sc =new Scanner(System.in);
       // int n =sc.nextInt();
int ch =1;
int[] a= new int[100];

    //String s= sc.next();
    int n = sc.nextInt();
    int q =sc.nextInt();
    List<String> list = new ArrayList<String>();
    List<Integer> intlist = new ArrayList<Integer>();
    List<String> sl = new ArrayList<String>();
    List<Integer> il = new ArrayList<Integer>();
for(int k=0;k<n;k++){
    list.add(sc.next());
    intlist.add(sc.nextInt());
}     
int q2= q;
int t=0;
    while ( list.size() !=0){
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    }
    for (int i=0;i<n;i++){
        System.out.println(sl.get(i)+ " "+ il.get(i));
    }
}
    }
 import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main{
    static public void  main(String[] av){
        int sum=0;

        Scanner sc =new Scanner(System.in);
       // int n =sc.nextInt();
int ch =1;
int[] a= new int[100];

    //String s= sc.next();
    int n = sc.nextInt();
    int q =sc.nextInt();
    List<String> list = new ArrayList<String>();
    List<Integer> intlist = new ArrayList<Integer>();
    List<String> sl = new ArrayList<String>();
    List<Integer> il = new ArrayList<Integer>();
for(int k=0;k<n;k++){
    list.add(sc.next());
    intlist.add(sc.nextInt());
}     
int q2= q;
int t=0;
    while ( list.size() !=0){
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    }
    for (int i=0;i<n;i++){
        System.out.println(sl.get(i)+ " "+ il.get(i));
    }
}
    } Main static public void  main(String[] av){
        int sum=0;

        Scanner sc =new Scanner(System.in);
       // int n =sc.nextInt();
int ch =1;
int[] a= new int[100];

    //String s= sc.next();
    int n = sc.nextInt();
    int q =sc.nextInt();
    List<String> list = new ArrayList<String>();
    List<Integer> intlist = new ArrayList<Integer>();
    List<String> sl = new ArrayList<String>();
    List<Integer> il = new ArrayList<Integer>();
for(int k=0;k<n;k++){
    list.add(sc.next());
    intlist.add(sc.nextInt());
}     
int q2= q;
int t=0;
    while ( list.size() !=0){
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    }
    for (int i=0;i<n;i++){
        System.out.println(sl.get(i)+ " "+ il.get(i));
    }
} main {
        int sum=0;

        Scanner sc =new Scanner(System.in);
       // int n =sc.nextInt();
int ch =1;
int[] a= new int[100];

    //String s= sc.next();
    int n = sc.nextInt();
    int q =sc.nextInt();
    List<String> list = new ArrayList<String>();
    List<Integer> intlist = new ArrayList<Integer>();
    List<String> sl = new ArrayList<String>();
    List<Integer> il = new ArrayList<Integer>();
for(int k=0;k<n;k++){
    list.add(sc.next());
    intlist.add(sc.nextInt());
}     
int q2= q;
int t=0;
    while ( list.size() !=0){
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    }
    for (int i=0;i<n;i++){
        System.out.println(sl.get(i)+ " "+ il.get(i));
    }
} int sum=0; sum 0 Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int ch =1; ch 1 int[] a= new int[100]; a new int[100] 100 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int q =sc.nextInt(); q sc.nextInt() sc.nextInt sc List<String> list = new ArrayList<String>(); list new ArrayList<String>() List<Integer> intlist = new ArrayList<Integer>(); intlist new ArrayList<Integer>() List<String> sl = new ArrayList<String>(); sl new ArrayList<String>() List<Integer> il = new ArrayList<Integer>(); il new ArrayList<Integer>() for(int k=0;k<n;k++){
    list.add(sc.next());
    intlist.add(sc.nextInt());
} int k=0; int k=0; k 0 k<n k n k++ k++ k {
    list.add(sc.next());
    intlist.add(sc.nextInt());
} {
    list.add(sc.next());
    intlist.add(sc.nextInt());
} list.add(sc.next()) list.add list sc.next() sc.next sc intlist.add(sc.nextInt()) intlist.add intlist sc.nextInt() sc.nextInt sc int q2= q; q2 q int t=0; t 0 while ( list.size() !=0){
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    } list.size() !=0 list.size() list.size list 0 {
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    } if (q2==0){
       q2=q;
   } q2==0 q2 0 {
       q2=q;
   } q2=q q2 q if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        } intlist.get(0) <=q2 intlist.get(0) intlist.get intlist 0 q2 {
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        } t+=intlist.get(0) t intlist.get(0) intlist.get intlist 0 q2=q2-intlist.get(0) q2 q2-intlist.get(0) q2 intlist.get(0) intlist.get intlist 0 sl.add(list.get(0)) sl.add sl list.get(0) list.get list 0 il.add(t) il.add il t intlist.remove(0) intlist.remove intlist 0 list.remove(0) list.remove list 0 q2=q q2 q {
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        } t+=q2 t q2 intlist.set(0,intlist.get(0)-q2) intlist.set intlist 0 intlist.get(0)-q2 intlist.get(0) intlist.get intlist 0 q2 q2=0 q2 0 int x=intlist.get(0); x intlist.get(0) intlist.get intlist 0 String y=list.get(0); y list.get(0) list.get list 0 intlist.remove(0) intlist.remove intlist 0 list.remove(0) list.remove list 0 intlist.add(x) intlist.add intlist x list.add(y) list.add list y for (int i=0;i<n;i++){
        System.out.println(sl.get(i)+ " "+ il.get(i));
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
        System.out.println(sl.get(i)+ " "+ il.get(i));
    } {
        System.out.println(sl.get(i)+ " "+ il.get(i));
    } System.out.println(sl.get(i)+ " "+ il.get(i)) System.out.println System.out System System.out sl.get(i)+ " "+ il.get(i) sl.get(i)+ " "+ il.get(i) sl.get(i) sl.get sl i " " il.get(i) il.get il i String[] av av
import java.util.List;
import java.util.ArrayList;

import java.util.Scanner;
class Main{
    static public void  main(String[] av){
        int sum=0;

        Scanner sc =new Scanner(System.in);
       // int n =sc.nextInt();
int ch =1;
int[] a= new int[100];

    //String s= sc.next();
    int n = sc.nextInt();
    int q =sc.nextInt();
    List<String> list = new ArrayList<String>();
    List<Integer> intlist = new ArrayList<Integer>();
    List<String> sl = new ArrayList<String>();
    List<Integer> il = new ArrayList<Integer>();
for(int k=0;k<n;k++){
    list.add(sc.next());
    intlist.add(sc.nextInt());
}     
int q2= q;
int t=0;
    while ( list.size() !=0){
   if (q2==0){
       q2=q;
   }
        if ( intlist.get(0) <=q2){
            t+=intlist.get(0);
q2=q2-intlist.get(0);
sl.add(list.get(0));
il.add(t);

intlist.remove(0);
list.remove(0);
q2=q;
        }
        else{
       t+=q2;     
intlist.set(0,intlist.get(0)-q2);
q2=0;
int x=intlist.get(0);
String y=list.get(0);
intlist.remove(0);
list.remove(0);
intlist.add(x);
list.add(y);
        }

    }
    for (int i=0;i<n;i++){
        System.out.println(sl.get(i)+ " "+ il.get(i));
    }
}
    }

