import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n n q q sum = 0 sum 0 num = 0; num 0 int[] time time end; end String[] name; name n = scan.nextInt() n scan.nextInt() scan.nextInt scan q = scan.nextInt() q scan.nextInt() scan.nextInt scan time = new int[n] time new int[n] n end = new int[n] end new int[n] n name = new String[n] name new String[n] n for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		} {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		} name[i] = scan.next() name[i] name i scan.next() scan.next scan time[i] = scan.nextInt() time[i] time i scan.nextInt() scan.nextInt scan while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		} num < n num n {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		} for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			} {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			} if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				} time[i] > 0 time[i] time i 0 {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				} if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					} time[i] <= q time[i] time i q {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} sum += time[i] sum time[i] time i end[num] = i end[num] end num i num++ num time[i] = -sum time[i] time i -sum sum {
						time[i] -= q;
						sum += q;
						
					} time[i] -= q time[i] time i q sum += q sum q for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		} {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		} System.out.println(name[end[i]] + " " + -time[end[i]]) System.out.println System.out System System.out name[end[i]] + " " + -time[end[i]] name[end[i]] + " " + -time[end[i]] name[end[i]] name end[i] end i " " -time[end[i]] time[end[i]] time end[i] end i scan.close() scan.close scan String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, q, sum = 0, num = 0;
		int[] time, end;
		String[] name;
		
		n = scan.nextInt();
		q = scan.nextInt();

		time = new int[n];
		end = new int[n];
		name = new String[n];
		
		for(int i = 0; i < n; i++) {
			name[i] = scan.next();
			time[i] = scan.nextInt();
		}
		
		while(num < n) {
			for(int i = 0; i < n; i++) {
				if(time[i] > 0) {
					if(time[i] <= q) {
						sum += time[i];
						end[num] = i;
						num++;
						time[i] = -sum;
						
					} else {
						time[i] -= q;
						sum += q;
						
					}
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.println(name[end[i]] + " " + -time[end[i]]);
		}
		
		scan.close();
	}
}