from collections import deque
def solve(n,t):
  q=deque([])
  for i in range(n):
    l=list(input().split())
    q.append(l)
  time=0
  while not len(q)==0:
    x=q.popleft()
    if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1])
n,t=map(int,input().split())
solve(n,t) from collections import deque def solve(n,t):
  q=deque([])
  for i in range(n):
    l=list(input().split())
    q.append(l)
  time=0
  while not len(q)==0:
    x=q.popleft()
    if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1]) solve q=deque([]) q deque([]) deque [] for i in range(n):
    l=list(input().split())
    q.append(l)
   i range(n) range n l=list(input().split()) l list(input().split()) list input().split() ().split () input split q.append(l) q.append q append l time=0 time 0 while not len(q)==0:
    x=q.popleft()
    if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1]) not len(q)==0 len(q)==0 len(q) len q 0 x=q.popleft() x q.popleft() q.popleft q popleft if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1]) int(x[1])-t>0 int(x[1])-t int(x[1]) int x[1] x 1 t 0 x[1]=str(int(x[1])-t) x[1] x 1 str(int(x[1])-t) str int(x[1])-t int(x[1]) int x[1] x 1 t time+=t time t q.append(x) q.append q append x print(x[0]+" "+str(time+int(x[1]))) print x[0]+" "+str(time+int(x[1])) x[0]+" " x[0] x 0 " " str(time+int(x[1])) str time+int(x[1]) time int(x[1]) int x[1] x 1 time+=int(x[1]) time int(x[1]) int x[1] x 1 n n t t n,t=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split t solve(n,t) solve n t n,t=map(int,input().split()) map(int,input().split()) n def solve(n,t):
  q=deque([])
  for i in range(n):
    l=list(input().split())
    q.append(l)
  time=0
  while not len(q)==0:
    x=q.popleft()
    if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1]) def solve(n,t):
  q=deque([])
  for i in range(n):
    l=list(input().split())
    q.append(l)
  time=0
  while not len(q)==0:
    x=q.popleft()
    if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1]) solve t=map(int,input().split()) map(int,input().split()) t
from collections import deque
def solve(n,t):
  q=deque([])
  for i in range(n):
    l=list(input().split())
    q.append(l)
  time=0
  while not len(q)==0:
    x=q.popleft()
    if int(x[1])-t>0:
      x[1]=str(int(x[1])-t)
      time+=t
      q.append(x)
    else:
      print(x[0]+" "+str(time+int(x[1])))
      time+=int(x[1])
n,t=map(int,input().split())
solve(n,t)
