from collections import deque

n,q=[int(i) for i in input().split()]
name=[0 for i in range(n)]
time=[0 for i in range(n)]
answer_name=[]
answer_time=[]
total_time=0

for i in range(n):
    name[i],time[i]=input().split()

d_name = deque(name)
d_time = deque(time)

while len(d_name)>0:

    a=d_name.popleft()
    b=int(d_time.popleft())

    if b>q:
        d_name.append(a)
        d_time.append(b-q)
        total_time=total_time+q

    else:
        total_time=total_time+b
        answer_name.append(a)
        answer_time.append(total_time)

for i in range(len(answer_time)):
    print(answer_name[i], answer_time[i])
 from collections import deque int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,q=[int(i) for i in input().split()] n [int(i) for i in input().split()] q 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 name=[0 for i in range(n)] name [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 time=[0 for i in range(n)] time [0 for i in range(n)] answer_name=[] answer_name [] answer_time=[] answer_time [] total_time=0 total_time 0 for i in range(n):
    name[i],time[i]=input().split() i range(n) range n name[i],time[i]=input().split() name[i] name i input().split() ().split () input split time[i] time i d_name = deque(name) d_name deque(name) deque name d_time = deque(time) d_time deque(time) deque time while len(d_name)>0:

    a=d_name.popleft()
    b=int(d_time.popleft())

    if b>q:
        d_name.append(a)
        d_time.append(b-q)
        total_time=total_time+q

    else:
        total_time=total_time+b
        answer_name.append(a)
        answer_time.append(total_time) len(d_name)>0 len(d_name) len d_name 0 a=d_name.popleft() a d_name.popleft() d_name.popleft d_name popleft b=int(d_time.popleft()) b int(d_time.popleft()) int d_time.popleft() d_time.popleft d_time popleft if b>q:
        d_name.append(a)
        d_time.append(b-q)
        total_time=total_time+q

    else:
        total_time=total_time+b
        answer_name.append(a)
        answer_time.append(total_time) b>q b q d_name.append(a) d_name.append d_name append a d_time.append(b-q) d_time.append d_time append b-q b q total_time=total_time+q total_time total_time+q total_time q total_time=total_time+b total_time total_time+b total_time b answer_name.append(a) answer_name.append answer_name append a answer_time.append(total_time) answer_time.append answer_time append total_time for i in range(len(answer_time)):
    print(answer_name[i], answer_time[i]) i range(len(answer_time)) range len(answer_time) len answer_time print(answer_name[i], answer_time[i]) print answer_name[i] answer_name i answer_time[i] answer_time i a=d_name.popleft() d_name.popleft() a b=int(d_time.popleft()) int(d_time.popleft()) b total_time=0 0 total_time n,q=[int(i) for i in input().split()] [int(i) for i in input().split()] n d_name = deque(name) deque(name) d_name d_time = deque(time) deque(time) d_time name=[0 for i in range(n)] [0 for i in range(n)] name answer_name=[] [] answer_name answer_time=[] [] answer_time time=[0 for i in range(n)] [0 for i in range(n)] time total_time=total_time+b total_time+b total_time q=[int(i) for i in input().split()] [int(i) for i in input().split()] q total_time=total_time+q total_time+q total_time
from collections import deque

n,q=[int(i) for i in input().split()]
name=[0 for i in range(n)]
time=[0 for i in range(n)]
answer_name=[]
answer_time=[]
total_time=0

for i in range(n):
    name[i],time[i]=input().split()

d_name = deque(name)
d_time = deque(time)

while len(d_name)>0:

    a=d_name.popleft()
    b=int(d_time.popleft())

    if b>q:
        d_name.append(a)
        d_time.append(b-q)
        total_time=total_time+q

    else:
        total_time=total_time+b
        answer_name.append(a)
        answer_time.append(total_time)

for i in range(len(answer_time)):
    print(answer_name[i], answer_time[i])

