N, Q = list(map(int, input().strip().split()))



A = []

D = {}

for l in range(N):

    n, t = input().strip().split()

    A.append([n, int(t)])



T = 0

while A:

    l = A.pop(0)

    if l[1] > Q:

        l[1] -= Q

        T += Q

        A.append(l)

    else:

        T += l[1]

        print((l[0], T))
from collections import deque

 

n,p=list(map(int ,input().split()))

que=deque([])

 

for i in range(n):

    name,time=input().split()

    time=int(time)

    que.append([name,time])

 

t=0

while len(que)>0:

    atop=que.popleft()

    spend=min(atop[1],p)

    atop[1]-=spend

    t+=spend

    if(atop[1]==0):

        print((atop[0],t))

    else:

        que.append(atop)

N, Q = list(map(int, input().strip().split()))
A = []
D = {}
for l in range(N):
    n, t = input().strip().split()
    A.append([n, int(t)])
T = 0
while A:
    l = A.pop(0)
    if l[1] > Q:
        l[1] -= Q
        T += Q
        A.append(l)
    else:
        T += l[1]
        print((l[0], T))

from collections import deque

n, p = list(map(int, input().split()))
que = deque([])
for i in range(n):
    name, time = input().split()
    time = int(time)
    que.append([name, time])
t = 0
while len(que) > 0:
    atop = que.popleft()
    spend = min(atop[1], p)
    atop[1] -= spend
    t += spend
    if atop[1] == 0:
        print((atop[0], t))
    else:
        que.append(atop)

-N, Q = list(map(int, input().strip().split())) -A = [] -D = {} -for l in range(N): -    n, t = input().strip().split() -    A.append([n, int(t)]) -T = 0 -while A: -    l = A.pop(0) -    if l[1] > Q: -        l[1] -= Q -        T += Q -        A.append(l) +from collections import deque + +n, p = list(map(int, input().split())) +que = deque([]) +for i in range(n): +    name, time = input().split() +    time = int(time) +    que.append([name, time]) +t = 0 +while len(que) > 0: +    atop = que.popleft() +    spend = min(atop[1], p) +    atop[1] -= spend +    t += spend +    if atop[1] == 0: +        print((atop[0], t)) -        T += l[1] -        print((l[0], T)) +        que.append(atop)