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

name = []

time = []

for i in range(n):

    a = input().split()

    name.append(a[0])

    time.append(int(a[1]))

s = 0

while name:

    if time[0]> q:

        time[0] -= q

        time.append(time.pop(0))

        name.append(name.pop(0))

        s += q

    else:

        s += time[0] 

        time.pop(0)

        print((name.pop(0),s))
from collections import deque



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

Q = deque()



for i in range(n):

    a = input().split()

    Q.append([a[0],int(a[1])])

s = 0



while Q:

    qt = Q.popleft()

    

    if qt[1] > q:

        Q.append([qt[0],qt[1]-q])

        s += q

    else:

        s += qt[1] 

        print((qt[0],s))
n, q = list(map(int, input().split()))
name = []
time = []
for i in range(n):
    a = input().split()
    name.append(a[0])
    time.append(int(a[1]))
s = 0
while name:
    if time[0] > q:
        time[0] -= q
        time.append(time.pop(0))
        name.append(name.pop(0))
        s += q
    else:
        s += time[0]
        time.pop(0)
        print((name.pop(0), s))

from collections import deque

n, q = list(map(int, input().split()))
Q = deque()
for i in range(n):
    a = input().split()
    Q.append([a[0], int(a[1])])
s = 0
while Q:
    qt = Q.popleft()
    if qt[1] > q:
        Q.append([qt[0], qt[1] - q])
        s += q
    else:
        s += qt[1]
        print((qt[0], s))

+from collections import deque + -name = [] -time = [] +Q = deque() -    name.append(a[0]) -    time.append(int(a[1])) +    Q.append([a[0], int(a[1])]) -while name: -    if time[0] > q: -        time[0] -= q -        time.append(time.pop(0)) -        name.append(name.pop(0)) +while Q: +    qt = Q.popleft() +    if qt[1] > q: +        Q.append([qt[0], qt[1] - q]) -        s += time[0] -        time.pop(0) -        print((name.pop(0), s)) +        s += qt[1] +        print((qt[0], s))