# coding: utf-8
# Here your code !
import collections

p,q=map(int,input().split())
count =0

deq = collections.deque()
finished=[]

while 1:
    try:
        deq.append(input().split())
        
    except EOFError:
        break

while deq:
    d = deq.popleft()
    d[1]=int(d[1])
    if d[1]<=q:
        count+=d[1]
        d[1]=count
        finished.append(map(str,d))
    elif d[1]>q:
        d[1]-=q
        count+=q
        deq.append(d)
for f in finished:
    print(" ".join(f)) import collections collections p,q=map(int,input().split()) p map(int,input().split()) map int input().split() ().split () input split q count =0 count 0 deq = collections.deque() deq collections.deque() collections.deque collections deque finished=[] finished [] while 1:
    try:
        deq.append(input().split())
        
    except EOFError:
        break 1 try:
        deq.append(input().split())
        
    except EOFError:
        break except EOFError:
        break break deq.append(input().split()) deq.append deq append input().split() ().split () input split while deq:
    d = deq.popleft()
    d[1]=int(d[1])
    if d[1]<=q:
        count+=d[1]
        d[1]=count
        finished.append(map(str,d))
    elif d[1]>q:
        d[1]-=q
        count+=q
        deq.append(d) deq d = deq.popleft() d deq.popleft() deq.popleft deq popleft d[1]=int(d[1]) d[1] d 1 int(d[1]) int d[1] d 1 if d[1]<=q:
        count+=d[1]
        d[1]=count
        finished.append(map(str,d))
    elif d[1]>q:
        d[1]-=q
        count+=q
        deq.append(d) d[1]<=q d[1] d 1 q count+=d[1] count d[1] d 1 d[1]=count d[1] d 1 count finished.append(map(str,d)) finished.append finished append map(str,d) map str d elif d[1]>q:
        d[1]-=q
        count+=q
        deq.append(d) d[1]>q d[1] d 1 q d[1]-=q d[1] d 1 q count+=q count q deq.append(d) deq.append deq append d for f in finished:
    print(" ".join(f)) f finished print(" ".join(f)) print " ".join(f) " ".join " " join f p,q=map(int,input().split()) map(int,input().split()) p count =0 0 count count+=d[1] d[1] count finished=[] [] finished q=map(int,input().split()) map(int,input().split()) q d = deq.popleft() deq.popleft() d count+=q q count deq = collections.deque() collections.deque() deq
# coding: utf-8
# Here your code !
import collections

p,q=map(int,input().split())
count =0

deq = collections.deque()
finished=[]

while 1:
    try:
        deq.append(input().split())
        
    except EOFError:
        break

while deq:
    d = deq.popleft()
    d[1]=int(d[1])
    if d[1]<=q:
        count+=d[1]
        d[1]=count
        finished.append(map(str,d))
    elif d[1]>q:
        d[1]-=q
        count+=q
        deq.append(d)
for f in finished:
    print(" ".join(f))