from collections import deque

n, q = map(int, input().split())
Q = deque()
for i in range(n):
    name,time = input().split()
    Q.append([name, int(time)])

sum =0
while Q:
    qt = Q.popleft()
    if qt[1] <= q:
        sum += qt[1]
        print(qt[0], sum)
    else:
        sum += q
        qt[1] -= q
        Q.append(qt) from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q Q = deque() Q deque() deque for i in range(n):
    name,time = input().split()
    Q.append([name, int(time)]) i range(n) range n name,time = input().split() name input().split() ().split () input split time Q.append([name, int(time)]) Q.append Q append [name, int(time)] name int(time) int time sum =0 sum 0 while Q:
    qt = Q.popleft()
    if qt[1] <= q:
        sum += qt[1]
        print(qt[0], sum)
    else:
        sum += q
        qt[1] -= q
        Q.append(qt) Q qt = Q.popleft() qt Q.popleft() Q.popleft Q popleft if qt[1] <= q:
        sum += qt[1]
        print(qt[0], sum)
    else:
        sum += q
        qt[1] -= q
        Q.append(qt) qt[1] <= q qt[1] qt 1 q sum += qt[1] sum qt[1] qt 1 print(qt[0], sum) print qt[0] qt 0 sum sum += q sum q qt[1] -= q qt[1] qt 1 q Q.append(qt) Q.append Q append qt sum =0 0 sum n, q = map(int, input().split()) map(int, input().split()) n Q = deque() deque() Q time = input().split() input().split() time sum += qt[1] qt[1] sum name,time = input().split() input().split() name q = map(int, input().split()) map(int, input().split()) q qt = Q.popleft() Q.popleft() qt sum += q q sum
from collections import deque

n, q = map(int, input().split())
Q = deque()
for i in range(n):
    name,time = input().split()
    Q.append([name, int(time)])

sum =0
while Q:
    qt = Q.popleft()
    if qt[1] <= q:
        sum += qt[1]
        print(qt[0], sum)
    else:
        sum += q
        qt[1] -= q
        Q.append(qt)