import java.util.Scanner;
import java.lang.Math;
import java.lang.System;
import java.io.*;
class Process{
  String n;
  int t;
}
class Main{
  private static int max = 100005;
  private static int head, tail;
  private static Process[] q=new Process[max];

  public static void initialize(){
    head = 0;
    tail = 0;
    return;
  }

  public static boolean isEmpty(){
    return head==tail;
  }

  public static boolean isFull(){
    return ((tail+1)%max==head);
  }

  public static void enqueue(String n, int t){
    if(isFull()) System.out.println("Error");
    q[tail]=new Process();
    q[tail].n=n;
    q[tail].t=t;
    //System.out.println(tail);
    tail=(tail+1)%max;
    //System.out.println(tail);
  }

  public static Process dequeue(){
    if(isEmpty()) System.out.println("Error");
    int x=head;
    head=(head+1)%max;
    return q[x];
  }

  public static void main(String args[]) throws Exception{
    Scanner stdIn=new Scanner(System.in);
    int namecnt=stdIn.nextInt();
    int quantum=stdIn.nextInt();
    int total=0;

    // InputStreamReader isr=new InputStreamReader(System.in);
    // BufferedReader br=new BufferedReader(isr);
    String line;
    for(int i=0;i<namecnt;i++){
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  }

    while(!isEmpty()){
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    }
  }
}

 import java.util.Scanner; Scanner java.util import java.lang.Math; Math java.lang import java.lang.System; System java.lang import java.io.*; io.* java class Process{
  String n;
  int t;
} Process String n; n int t; t class Main{
  private static int max = 100005;
  private static int head, tail;
  private static Process[] q=new Process[max];

  public static void initialize(){
    head = 0;
    tail = 0;
    return;
  }

  public static boolean isEmpty(){
    return head==tail;
  }

  public static boolean isFull(){
    return ((tail+1)%max==head);
  }

  public static void enqueue(String n, int t){
    if(isFull()) System.out.println("Error");
    q[tail]=new Process();
    q[tail].n=n;
    q[tail].t=t;
    //System.out.println(tail);
    tail=(tail+1)%max;
    //System.out.println(tail);
  }

  public static Process dequeue(){
    if(isEmpty()) System.out.println("Error");
    int x=head;
    head=(head+1)%max;
    return q[x];
  }

  public static void main(String args[]) throws Exception{
    Scanner stdIn=new Scanner(System.in);
    int namecnt=stdIn.nextInt();
    int quantum=stdIn.nextInt();
    int total=0;

    // InputStreamReader isr=new InputStreamReader(System.in);
    // BufferedReader br=new BufferedReader(isr);
    String line;
    for(int i=0;i<namecnt;i++){
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  }

    while(!isEmpty()){
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    }
  }
} Main private static int max = 100005; max 100005 private static int head head tail; tail private static Process[] q=new Process[max]; q new Process[max] max public static void initialize(){
    head = 0;
    tail = 0;
    return;
  } initialize {
    head = 0;
    tail = 0;
    return;
  } head = 0 head 0 tail = 0 tail 0 return; public static boolean isEmpty(){
    return head==tail;
  } isEmpty {
    return head==tail;
  } return head==tail; head==tail head tail public static boolean isFull(){
    return ((tail+1)%max==head);
  } isFull {
    return ((tail+1)%max==head);
  } return ((tail+1)%max==head); ((tail+1)%max==head) (tail+1)%max (tail+1) tail 1 max head public static void enqueue(String n, int t){
    if(isFull()) System.out.println("Error");
    q[tail]=new Process();
    q[tail].n=n;
    q[tail].t=t;
    //System.out.println(tail);
    tail=(tail+1)%max;
    //System.out.println(tail);
  } enqueue {
    if(isFull()) System.out.println("Error");
    q[tail]=new Process();
    q[tail].n=n;
    q[tail].t=t;
    //System.out.println(tail);
    tail=(tail+1)%max;
    //System.out.println(tail);
  } if(isFull()) System.out.println("Error"); isFull() isFull System.out.println("Error") System.out.println System.out System System.out "Error" q[tail]=new Process() q[tail] q tail new Process() q[tail].n=n q[tail].n q[tail] q tail q[tail].n n q[tail].t=t q[tail].t q[tail] q tail q[tail].t t tail=(tail+1)%max tail (tail+1)%max (tail+1) tail 1 max String n n int t t public static Process dequeue(){
    if(isEmpty()) System.out.println("Error");
    int x=head;
    head=(head+1)%max;
    return q[x];
  } dequeue {
    if(isEmpty()) System.out.println("Error");
    int x=head;
    head=(head+1)%max;
    return q[x];
  } if(isEmpty()) System.out.println("Error"); isEmpty() isEmpty System.out.println("Error") System.out.println System.out System System.out "Error" int x=head; x head head=(head+1)%max head (head+1)%max (head+1) head 1 max return q[x]; q[x] q x public static void main(String args[]) throws Exception{
    Scanner stdIn=new Scanner(System.in);
    int namecnt=stdIn.nextInt();
    int quantum=stdIn.nextInt();
    int total=0;

    // InputStreamReader isr=new InputStreamReader(System.in);
    // BufferedReader br=new BufferedReader(isr);
    String line;
    for(int i=0;i<namecnt;i++){
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  }

    while(!isEmpty()){
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    }
  } main {
    Scanner stdIn=new Scanner(System.in);
    int namecnt=stdIn.nextInt();
    int quantum=stdIn.nextInt();
    int total=0;

    // InputStreamReader isr=new InputStreamReader(System.in);
    // BufferedReader br=new BufferedReader(isr);
    String line;
    for(int i=0;i<namecnt;i++){
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  }

    while(!isEmpty()){
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    }
  } Scanner stdIn=new Scanner(System.in); stdIn new Scanner(System.in) int namecnt=stdIn.nextInt(); namecnt stdIn.nextInt() stdIn.nextInt stdIn int quantum=stdIn.nextInt(); quantum stdIn.nextInt() stdIn.nextInt stdIn int total=0; total 0 String line; line for(int i=0;i<namecnt;i++){
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  } int i=0; int i=0; i 0 i<namecnt i namecnt i++ i++ i {
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  } {
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  } String n=stdIn.next(); n stdIn.next() stdIn.next stdIn int t=stdIn.nextInt(); t stdIn.nextInt() stdIn.nextInt stdIn enqueue(n,t) enqueue n t while(!isEmpty()){
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    } !isEmpty() isEmpty() isEmpty {
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    } Process temp=new Process(); temp new Process() temp=dequeue() temp dequeue() dequeue if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      } temp.t>quantum temp.t temp temp.t quantum {
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      } temp.t-=quantum temp.t temp temp.t quantum enqueue(temp.n,temp.t) enqueue temp.n temp temp.n temp.t temp temp.t total+=quantum total quantum {
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      } total+=temp.t total temp.t temp temp.t System.out.println(temp.n+" "+total) System.out.println System.out System System.out temp.n+" "+total temp.n+" "+total temp.n temp temp.n " " total String args[] args
import java.util.Scanner;
import java.lang.Math;
import java.lang.System;
import java.io.*;
class Process{
  String n;
  int t;
}
class Main{
  private static int max = 100005;
  private static int head, tail;
  private static Process[] q=new Process[max];

  public static void initialize(){
    head = 0;
    tail = 0;
    return;
  }

  public static boolean isEmpty(){
    return head==tail;
  }

  public static boolean isFull(){
    return ((tail+1)%max==head);
  }

  public static void enqueue(String n, int t){
    if(isFull()) System.out.println("Error");
    q[tail]=new Process();
    q[tail].n=n;
    q[tail].t=t;
    //System.out.println(tail);
    tail=(tail+1)%max;
    //System.out.println(tail);
  }

  public static Process dequeue(){
    if(isEmpty()) System.out.println("Error");
    int x=head;
    head=(head+1)%max;
    return q[x];
  }

  public static void main(String args[]) throws Exception{
    Scanner stdIn=new Scanner(System.in);
    int namecnt=stdIn.nextInt();
    int quantum=stdIn.nextInt();
    int total=0;

    // InputStreamReader isr=new InputStreamReader(System.in);
    // BufferedReader br=new BufferedReader(isr);
    String line;
    for(int i=0;i<namecnt;i++){
      String n=stdIn.next();
      int t=stdIn.nextInt();
      enqueue(n,t);
      //String[] str=line.split(" ");
      // enqueue(str[0],Integer.parseInt(str[1]));

      //System.out.println(line);
  }

    while(!isEmpty()){
      Process temp=new Process();
      temp=dequeue();
      //System.out.println(temp.n+temp.t);
      if(temp.t>quantum){
        temp.t-=quantum;
        enqueue(temp.n,temp.t);
        total+=quantum;
      }
      else{
        total+=temp.t;
        System.out.println(temp.n+" "+total);
      }
    }
  }
}


