import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
    public static void main(String[] args)
    {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    }
} Main public static void main(String[] args)
    {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    } main {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    } Deque<String> name = new ArrayDeque<String>(); name new ArrayDeque<String>() Deque<Integer> time = new ArrayDeque<Integer>(); time new ArrayDeque<Integer>() Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int quantum = scan.nextInt(); quantum scan.nextInt() scan.nextInt scan for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        } {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        } name.offerLast(scan.next()) name.offerLast name scan.next() scan.next scan time.offerLast(scan.nextInt()) time.offerLast time scan.nextInt() scan.nextInt scan String process_name; process_name int process_time; process_time int elapsed_time = 0; elapsed_time 0 while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        } (process_name = name.pollFirst())!=null (process_name = name.pollFirst()) process_name name.pollFirst() name.pollFirst name null {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        } process_time = time.pollFirst() process_time time.pollFirst() time.pollFirst time if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            } process_time > quantum process_time quantum {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            } name.offerLast(process_name) name.offerLast name process_name time.offerLast(process_time - quantum) time.offerLast time process_time - quantum process_time quantum elapsed_time += quantum elapsed_time quantum {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            } elapsed_time += process_time elapsed_time process_time System.out.println(process_name + " " + elapsed_time) System.out.println System.out System System.out process_name + " " + elapsed_time process_name + " " + elapsed_time process_name " " elapsed_time String[] args args public class Main
{
    public static void main(String[] args)
    {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    }
} public class Main
{
    public static void main(String[] args)
    {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    }
} Main
import java.io.*;
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Deque<String> name = new ArrayDeque<String>();
        Deque<Integer> time = new ArrayDeque<Integer>();
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int quantum = scan.nextInt();

        for(int i=0; i<n; i++)
        {
            name.offerLast(scan.next());
            time.offerLast(scan.nextInt());
        }

        String process_name;
        int process_time;
        int elapsed_time = 0;
        while((process_name = name.pollFirst())!=null)
        {
            process_time = time.pollFirst();
            if(process_time > quantum)
            {
                name.offerLast(process_name);
                time.offerLast(process_time - quantum);
                elapsed_time += quantum;
            }
            else
            {
                elapsed_time += process_time;
                System.out.println(process_name + " " + elapsed_time);
            }
        }
    }
}