import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
     
public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    }
 
    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
}
 import java.io.InputStream; InputStream java.io import java.io.IOException; IOException java.io import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util import java.util.InputMismatchException; InputMismatchException java.util import java.util.NoSuchElementException; NoSuchElementException java.util import java.util.PriorityQueue; PriorityQueue java.util public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    }
 
    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
} Main static InputReader ir; ir static PrintWriter out; out static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    } solve {
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    } Deque<int[]> que=new ArrayDeque<int[]>(); que new ArrayDeque<int[]>() int n=ir.nextInt(); n ir.nextInt() ir.nextInt ir int q=ir.nextInt(); q ir.nextInt() ir.nextInt ir String[] name=new String[n]; name new String[n] n for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	} {
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	} name[i]=ir.next() name[i] name i ir.next() ir.next ir que.offerLast(new int[]{i,ir.nextInt()}) que.offerLast que new int[]{i,ir.nextInt()} int cur=0; cur 0 while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	} !que.isEmpty() que.isEmpty() que.isEmpty que {
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	} int[] a=que.pollFirst(); a que.pollFirst() que.pollFirst que if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    } a[1]<=q a[1] a 1 q {
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    } cur+=a[1] cur a[1] a 1 out.println(name[a[0]]+" "+cur) out.println out name[a[0]]+" "+cur name[a[0]]+" "+cur name[a[0]] name a[0] a 0 " " cur {
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    } cur+=q cur q que.offerLast(new int[]{a[0],a[1]-q}) que.offerLast que new int[]{a[0],a[1]-q} public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     } main {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     } ir = new InputReader(System.in) ir new InputReader(System.in) out = new PrintWriter(System.out) out new PrintWriter(System.out) solve() solve out.flush() out.flush out String[] args args static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    } InputReader private InputStream in; in private byte[] buffer=new byte[1024]; buffer new byte[1024] 1024 private int curbuf; curbuf private int lenbuf; lenbuf public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;} InputReader {this.in=in; this.curbuf=this.lenbuf=0;} this.in=in this.in this this.in in this.curbuf=this.lenbuf=0 this.curbuf this this.curbuf this.lenbuf=0 this.lenbuf this this.lenbuf 0 InputStream in in public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	} hasNextByte {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	} if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    } curbuf>=lenbuf curbuf lenbuf {
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    } curbuf= 0 curbuf 0 try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		} catch(IOException e) {
		    throw new InputMismatchException();
		} IOException e {
		    throw new InputMismatchException();
		} throw new InputMismatchException(); new InputMismatchException() {
		    lenbuf=in.read(buffer);
		} lenbuf=in.read(buffer) lenbuf in.read(buffer) in.read in buffer if(lenbuf<=0) return false; lenbuf<=0 lenbuf 0 return false; false return true; true private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;} readByte {if(hasNextByte()) return buffer[curbuf++]; else return -1;} if(hasNextByte()) return buffer[curbuf++]; else return -1; hasNextByte() hasNextByte return buffer[curbuf++]; buffer[curbuf++] buffer curbuf++ curbuf return -1; -1 1 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);} isSpaceChar {return !(c>=33&&c<=126);} return !(c>=33&&c<=126); !(c>=33&&c<=126) (c>=33&&c<=126) c>=33 c 33 c<=126 c 126 int c c private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;} skip {while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;} while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++; hasNextByte()&&isSpaceChar(buffer[curbuf]) hasNextByte() hasNextByte isSpaceChar(buffer[curbuf]) isSpaceChar buffer[curbuf] buffer curbuf curbuf++ curbuf public boolean hasNext(){skip(); return hasNextByte();} hasNext {skip(); return hasNextByte();} skip() skip return hasNextByte(); hasNextByte() hasNextByte public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	} next {
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	} if(!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() StringBuilder sb=new StringBuilder(); sb new StringBuilder() int b=readByte(); b readByte() readByte while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    } !isSpaceChar(b) isSpaceChar(b) isSpaceChar b {
		sb.appendCodePoint(b);
		b=readByte();
	    } sb.appendCodePoint(b) sb.appendCodePoint sb b b=readByte() b readByte() readByte return sb.toString(); sb.toString() sb.toString sb public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	} nextInt {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	} if(!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() int c=readByte(); c readByte() readByte while (isSpaceChar(c)) c=readByte(); isSpaceChar(c) isSpaceChar c c=readByte() c readByte() readByte boolean minus=false; minus false if (c=='-') {
		minus=true;
		c=readByte();
	    } c=='-' c '-' {
		minus=true;
		c=readByte();
	    } minus=true minus true c=readByte() c readByte() readByte int res=0; res 0 do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    } if(c<'0'||c>'9') throw new InputMismatchException(); c<'0'||c>'9' c<'0' c '0' c>'9' c '9' throw new InputMismatchException(); new InputMismatchException() res=res*10+c-'0' res res*10+c-'0' res*10+c res*10 res 10 c '0' c=readByte() c readByte() readByte return (minus)?-res:res; (minus)?-res:res (minus) -res res res public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	} nextLong {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	} if(!hasNext()) throw new NoSuchElementException(); !hasNext() hasNext() hasNext throw new NoSuchElementException(); new NoSuchElementException() int c=readByte(); c readByte() readByte while (isSpaceChar(c)) c=readByte(); isSpaceChar(c) isSpaceChar c c=readByte() c readByte() readByte boolean minus=false; minus false if (c=='-') {
		minus=true;
		c=readByte();
	    } c=='-' c '-' {
		minus=true;
		c=readByte();
	    } minus=true minus true c=readByte() c readByte() readByte long res = 0; res 0 do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    } if(c<'0'||c>'9') throw new InputMismatchException(); c<'0'||c>'9' c<'0' c '0' c>'9' c '9' throw new InputMismatchException(); new InputMismatchException() res=res*10+c-'0' res res*10+c-'0' res*10+c res*10 res 10 c '0' c=readByte() c readByte() readByte return (minus)?-res:res; (minus)?-res:res (minus) -res res res public double nextDouble(){return Double.parseDouble(next());} nextDouble {return Double.parseDouble(next());} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	} nextIntArray {
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	} int[] a=new int[n]; a new int[n] n for(int i=0;i<n;i++)
		a[i]=nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=nextInt(); a[i]=nextInt() a[i] a i nextInt() nextInt return a; a int n n public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	} nextCharMap {
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	} char[][] map=new char[n][m]; map new char[n][m] n m for(int i=0;i<n;i++)
		map[i]=next().toCharArray(); int i=0; int i=0; i 0 i<n i n i++ i++ i map[i]=next().toCharArray(); map[i]=next().toCharArray() map[i] map i next().toCharArray() next().toCharArray next() next return map; map int n n int m m public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    }
 
    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
} public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    }
 
    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
} Main
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
     
public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
        Deque<int[]> que=new ArrayDeque<int[]>();
	int n=ir.nextInt();
	int q=ir.nextInt();
	String[] name=new String[n];
	for(int i=0;i<n;i++){
	    name[i]=ir.next();
	    que.offerLast(new int[]{i,ir.nextInt()});
	}
	int cur=0;
	while(!que.isEmpty()){
	    int[] a=que.pollFirst();
	    if(a[1]<=q){
		cur+=a[1];
		out.println(name[a[0]]+" "+cur);
	    }
	    else{
		cur+=q;
		que.offerLast(new int[]{a[0],a[1]-q});
	    }
	}
    }
 
    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
}

