import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main
{
    static class Process {
        private String name;
        private int time;

        public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        }

        public String getName()
        {
            return this.name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getTime()
        {
            return this.time;
        }
        public void setTime(int time)
        {
            this.time = time;
        }
    }

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    }

} import java.util.ArrayList; ArrayList java.util import java.util.LinkedList; LinkedList java.util import java.util.List; List java.util import java.util.Queue; Queue java.util import java.util.Scanner; Scanner java.util public class Main
{
    static class Process {
        private String name;
        private int time;

        public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        }

        public String getName()
        {
            return this.name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getTime()
        {
            return this.time;
        }
        public void setTime(int time)
        {
            this.time = time;
        }
    }

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    }

} Main public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    } main {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) Queue<Process> queue = new LinkedList<Process>(); queue new LinkedList<Process>() int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int q = scan.nextInt(); q scan.nextInt() scan.nextInt scan Process[] p = new Process[n]; p new Process[n] n for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        } {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        } String name = scan.next(); name scan.next() scan.next scan int time = scan.nextInt(); time scan.nextInt() scan.nextInt scan p[i] = new Process(name, time) p[i] p i new Process(name, time) queue.offer(p[i]) queue.offer queue p[i] p i List<Process> finishProcesses = new ArrayList<Main.Process>(); finishProcesses new ArrayList<Main.Process>() int currentTime = 0; currentTime 0 while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        } queue.size() > 0 queue.size() queue.size queue 0 {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        } Process current = queue.poll(); current queue.poll() queue.poll queue if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            } current.getTime() > q current.getTime() current.getTime current q {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            } current.setTime(current.getTime() - q) current.setTime current current.getTime() - q current.getTime() current.getTime current q queue.offer(current) queue.offer queue current currentTime += q currentTime q {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            } finishProcesses.add(new Process(current.name, currentTime + current.getTime())) finishProcesses.add finishProcesses new Process(current.name, currentTime + current.getTime()) currentTime += current.getTime() currentTime current.getTime() current.getTime current for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        } Process process finishProcesses {
            System.out.println(process.name + " " + process.time);
        } {
            System.out.println(process.name + " " + process.time);
        } System.out.println(process.name + " " + process.time) System.out.println System.out System System.out process.name + " " + process.time process.name + " " + process.time process.name process process.name " " process.time process process.time scan.close() scan.close scan String[] args args static class Process {
        private String name;
        private int time;

        public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        }

        public String getName()
        {
            return this.name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getTime()
        {
            return this.time;
        }
        public void setTime(int time)
        {
            this.time = time;
        }
    } Process private String name; name private int time; time public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        } Process {
            this.name = name;
            this.time = time;
        } this.name = name this.name this this.name name this.time = time this.time this this.time time String name name int time time public String getName()
        {
            return this.name;
        } getName {
            return this.name;
        } return this.name; this.name this this.name public void setName(String name)
        {
            this.name = name;
        } setName {
            this.name = name;
        } this.name = name this.name this this.name name String name name public int getTime()
        {
            return this.time;
        } getTime {
            return this.time;
        } return this.time; this.time this this.time public void setTime(int time)
        {
            this.time = time;
        } setTime {
            this.time = time;
        } this.time = time this.time this this.time time int time time public class Main
{
    static class Process {
        private String name;
        private int time;

        public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        }

        public String getName()
        {
            return this.name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getTime()
        {
            return this.time;
        }
        public void setTime(int time)
        {
            this.time = time;
        }
    }

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    }

} public class Main
{
    static class Process {
        private String name;
        private int time;

        public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        }

        public String getName()
        {
            return this.name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getTime()
        {
            return this.time;
        }
        public void setTime(int time)
        {
            this.time = time;
        }
    }

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    }

} Main
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main
{
    static class Process {
        private String name;
        private int time;

        public Process(String name, int time)
        {
            this.name = name;
            this.time = time;
        }

        public String getName()
        {
            return this.name;
        }
        public void setName(String name)
        {
            this.name = name;
        }
        public int getTime()
        {
            return this.time;
        }
        public void setTime(int time)
        {
            this.time = time;
        }
    }

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Queue<Process> queue = new LinkedList<Process>();
        int n = scan.nextInt();
        int q = scan.nextInt();

        Process[] p = new Process[n];

        for (int i = 0; i < n; i++)
        {
            String name = scan.next();
            int time = scan.nextInt();
            p[i] = new Process(name, time);
            queue.offer(p[i]);
        }

        List<Process> finishProcesses = new ArrayList<Main.Process>();

        int currentTime = 0;
        while (queue.size() > 0) {
            Process current = queue.poll();
            if (current.getTime() > q) {
                current.setTime(current.getTime() - q);
                queue.offer(current);
                currentTime += q;
            }
            else {
                finishProcesses.add(new Process(current.name, currentTime + current.getTime()));
                currentTime += current.getTime();
            }
        }

        for (Process process : finishProcesses)
        {
            System.out.println(process.name + " " + process.time);
        }

        scan.close();
    }

}