import java.util.LinkedList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    }
} import java.util.LinkedList; LinkedList java.util import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int clock = scan.nextInt(); clock scan.nextInt() scan.nextInt scan int time = 0; time 0 LinkedList<String> names = new LinkedList<>(); names new LinkedList<>() LinkedList<Integer> amounts = new LinkedList<>(); amounts new LinkedList<>() for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        } int x =0; int x =0; x 0 x < n x n x++ x++ x {
            names.add(scan.next());
            amounts.add(scan.nextInt());
        } {
            names.add(scan.next());
            amounts.add(scan.nextInt());
        } names.add(scan.next()) names.add names scan.next() scan.next scan amounts.add(scan.nextInt()) amounts.add amounts scan.nextInt() scan.nextInt scan while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        } !amounts.isEmpty() amounts.isEmpty() amounts.isEmpty amounts {
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        } String name = names.removeFirst(); name names.removeFirst() names.removeFirst names int amount = amounts.removeFirst(); amount amounts.removeFirst() amounts.removeFirst amounts if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            } amount <= clock amount clock {
                time = time + amount;
                System.out.println(name + " " + time);
            } time = time + amount time time + amount time amount System.out.println(name + " " + time) System.out.println System.out System System.out name + " " + time name + " " + time name " " time {
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            } time = time + clock time time + clock time clock amount = amount - clock amount amount - clock amount clock names.add(name) names.add names name amounts.add(amount) amounts.add amounts amount String[] args args public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    }
} public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    }
} Main
import java.util.LinkedList;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int clock = scan.nextInt();
        int time = 0;
        LinkedList<String> names = new LinkedList<>();
        LinkedList<Integer> amounts = new LinkedList<>();
        for(int x =0; x < n; x++){
            names.add(scan.next());
            amounts.add(scan.nextInt());
        }
        while(!amounts.isEmpty()){
            String name = names.removeFirst();
            int amount = amounts.removeFirst();
            if(amount <= clock){
                time = time + amount;
                System.out.println(name + " " + time);
            }
            else{
                time = time + clock;
                amount = amount - clock;
                names.add(name);
                amounts.add(amount);
            }

        }

    }
}
