import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;

/**
 * Created by ??\??? on 2016/12/7.
 */

public class Main {
    static int si(String s){
        return Integer.parseInt(s);
    }
    static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    }
    public static void main(String[] args) throws Exception{
        run(args);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Queue; Queue java.util public class Main {
    static int si(String s){
        return Integer.parseInt(s);
    }
    static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    }
    public static void main(String[] args) throws Exception{
        run(args);
    }
} Main static int si(String s){
        return Integer.parseInt(s);
    } si {
        return Integer.parseInt(s);
    } return Integer.parseInt(s); Integer.parseInt(s) Integer.parseInt Integer s String s s static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    } run {
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    } BufferedReader scan = new BufferedReader(new InputStreamReader(System.in)); scan new BufferedReader(new InputStreamReader(System.in)) String[] lines = scan.readLine().split(" "); lines scan.readLine().split(" ") scan.readLine().split scan.readLine() scan.readLine scan " " int T = si(lines[0]); T si(lines[0]) si lines[0] lines 0 int H = si(lines[1]); H si(lines[1]) si lines[1] lines 1 Map<String,Integer> m = new HashMap<>(); m new HashMap<>() Queue<String> q = new ArrayDeque<>(); q new ArrayDeque<>() Queue<String> done = new ArrayDeque<>(); done new ArrayDeque<>() for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        } int i = 0; int i = 0; i 0 i<T i T i++ i++ i {
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        } {
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        } lines = scan.readLine().split(" ") lines scan.readLine().split(" ") scan.readLine().split scan.readLine() scan.readLine scan " " m.put(lines[0],si(lines[1])) m.put m lines[0] lines 0 si(lines[1]) si lines[1] lines 1 q.add(lines[0]) q.add q lines[0] lines 0 int time =0; time 0 while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        } T>0 T 0 {
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        } String w = q.poll(); w q.poll() q.poll q int ti = m.get(w)-H; ti m.get(w)-H m.get(w) m.get m w H if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            } ti>0 ti 0 {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            } q.add(w) q.add q w m.replace(w,ti) m.replace m w ti time+=H time H {
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            } time+=m.get(w) time m.get(w) m.get m w done.add(w+" "+String.valueOf(time)) done.add done w+" "+String.valueOf(time) w+" "+String.valueOf(time) w " " String.valueOf(time) String.valueOf String time m.replace(w,0) m.replace m w 0 T-- T for(String s: done){
            System.out.println(s);
        } String s done {
            System.out.println(s);
        } {
            System.out.println(s);
        } System.out.println(s) System.out.println System.out System System.out s String[] args args public static void main(String[] args) throws Exception{
        run(args);
    } main {
        run(args);
    } run(args) run args String[] args args public class Main {
    static int si(String s){
        return Integer.parseInt(s);
    }
    static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    }
    public static void main(String[] args) throws Exception{
        run(args);
    }
} public class Main {
    static int si(String s){
        return Integer.parseInt(s);
    }
    static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    }
    public static void main(String[] args) throws Exception{
        run(args);
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;

/**
 * Created by ??\??? on 2016/12/7.
 */

public class Main {
    static int si(String s){
        return Integer.parseInt(s);
    }
    static void run(String[] args) throws Exception{
        BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = scan.readLine().split(" ");
        int T = si(lines[0]);
        int H = si(lines[1]);
        Map<String,Integer> m = new HashMap<>();
        Queue<String> q = new ArrayDeque<>();
        Queue<String> done = new ArrayDeque<>();
        for(int i = 0;i<T;i++){
            lines = scan.readLine().split(" ");
            m.put(lines[0],si(lines[1]));
            q.add(lines[0]);
        }
        int time =0;
        while(T>0){
            String w = q.poll();
            int ti = m.get(w)-H;
            if(ti>0) {
                q.add(w);
                m.replace(w,ti);
                time+=H;
            }
            else{
                time+=m.get(w);
                done.add(w+" "+String.valueOf(time));
                m.replace(w,0);
                T--;
            }
        }
        for(String s: done){
            System.out.println(s);
        }
    }
    public static void main(String[] args) throws Exception{
        run(args);
    }
}