
import java.util.*;


class Main
{
    public static void main(String[] args)throws Exception
    {
        Scanner sc = new Scanner(System.in);
        Deque <String> que = new ArrayDeque <>(); 
        String []s = new String [2];  
        int n = sc.nextInt();
        int quan = sc.nextInt();
        for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        }
        Iterator itr = que.iterator();
        int time = 0;
        while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        }
    }
}
       


 import java.util.*; util.* java class Main
{
    public static void main(String[] args)throws Exception
    {
        Scanner sc = new Scanner(System.in);
        Deque <String> que = new ArrayDeque <>(); 
        String []s = new String [2];  
        int n = sc.nextInt();
        int quan = sc.nextInt();
        for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        }
        Iterator itr = que.iterator();
        int time = 0;
        while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        }
    }
} Main public static void main(String[] args)throws Exception
    {
        Scanner sc = new Scanner(System.in);
        Deque <String> que = new ArrayDeque <>(); 
        String []s = new String [2];  
        int n = sc.nextInt();
        int quan = sc.nextInt();
        for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        }
        Iterator itr = que.iterator();
        int time = 0;
        while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        Deque <String> que = new ArrayDeque <>(); 
        String []s = new String [2];  
        int n = sc.nextInt();
        int quan = sc.nextInt();
        for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        }
        Iterator itr = que.iterator();
        int time = 0;
        while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) Deque <String> que = new ArrayDeque <>(); que new ArrayDeque <>() String []s = new String [2]; s new String [2] 2 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int quan = sc.nextInt(); quan sc.nextInt() sc.nextInt sc for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            que.add(sc.next()+" "+sc.next());
        } {
            que.add(sc.next()+" "+sc.next());
        } que.add(sc.next()+" "+sc.next()) que.add que sc.next()+" "+sc.next() sc.next()+" "+sc.next() sc.next() sc.next sc " " sc.next() sc.next sc Iterator itr = que.iterator(); itr que.iterator() que.iterator que int time = 0; time 0 while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        } true {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        } try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            } catch(NoSuchElementException e) 
            {
                break;
            } NoSuchElementException e {
                break;
            } break; {
                s= que.getFirst().split(" ");
            } s= que.getFirst().split(" ") s que.getFirst().split(" ") que.getFirst().split que.getFirst() que.getFirst que " " int num = Integer.parseInt(s[1]); num Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            } num>quan num quan {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            } time =  quan + time time quan + time quan time num = num-quan num num-quan num quan que.removeFirst() que.removeFirst que que.add(s[0].concat(" "+ String.valueOf(num))) que.add que s[0].concat(" "+ String.valueOf(num)) s[0].concat s[0] s 0 " "+ String.valueOf(num) " " String.valueOf(num) String.valueOf String num if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            } num<=quan num quan {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            } time =  num + time time num + time num time que.removeFirst() que.removeFirst que System.out.println(s[0]+" "+ time) System.out.println System.out System System.out s[0]+" "+ time s[0]+" "+ time s[0] s 0 " " time String[] args args

import java.util.*;


class Main
{
    public static void main(String[] args)throws Exception
    {
        Scanner sc = new Scanner(System.in);
        Deque <String> que = new ArrayDeque <>(); 
        String []s = new String [2];  
        int n = sc.nextInt();
        int quan = sc.nextInt();
        for(int i = 0; i<n;i++) 
        {
            que.add(sc.next()+" "+sc.next());
        }
        Iterator itr = que.iterator();
        int time = 0;
        while(true)
        {
            try
            {
                s= que.getFirst().split(" ");
            }
            catch(NoSuchElementException e) 
            {
                break;
            }
            int num = Integer.parseInt(s[1]);
            if(num>quan) 
            {
                time =  quan + time;
                num = num-quan;
                que.removeFirst();
                que.add(s[0].concat(" "+ String.valueOf(num)));
            }
            else if (num<=quan)
            {
                time =  num + time;
                que.removeFirst();
                System.out.println(s[0]+" "+ time);
            }
        }
    }
}
       



