a=input().split()
a=[int(i) for i in a]
b=[]
cnt=0
time=0
for i in range(a[0]):
  b.append(input().split())
  cnt+=int(b[i][1])
i=0
while cnt!=time:
  if int(b[i][1])<=a[1]:
    time+=int(b[i][1])
    print(b[i][0],time)
    b.pop(0)
  else: 
    b[i][1]=int(b[i][1])-a[1]
    time+=a[1]
    b.append(b.pop(i))
     a=input().split() a input().split() ().split () input split int(i) for i in a for i in a i a for i in a int(i) int i a=[int(i) for i in a] a [int(i) for i in a] b=[] b [] cnt=0 cnt 0 time=0 time 0 for i in range(a[0]):
  b.append(input().split())
  cnt+=int(b[i][1]) i range(a[0]) range a[0] a 0 b.append(input().split()) b.append b append input().split() ().split () input split cnt+=int(b[i][1]) cnt int(b[i][1]) int b[i][1] [i] b i 1 i=0 i 0 while cnt!=time:
  if int(b[i][1])<=a[1]:
    time+=int(b[i][1])
    print(b[i][0],time)
    b.pop(0)
  else: 
    b[i][1]=int(b[i][1])-a[1]
    time+=a[1]
    b.append(b.pop(i))
     cnt!=time cnt time if int(b[i][1])<=a[1]:
    time+=int(b[i][1])
    print(b[i][0],time)
    b.pop(0)
  else: 
    b[i][1]=int(b[i][1])-a[1]
    time+=a[1]
    b.append(b.pop(i))
     int(b[i][1])<=a[1] int(b[i][1]) int b[i][1] [i] b i 1 a[1] a 1 time+=int(b[i][1]) time int(b[i][1]) int b[i][1] [i] b i 1 print(b[i][0],time) print b[i][0] [i] b i 0 time b.pop(0) b.pop b pop 0 b[i][1]=int(b[i][1])-a[1] b[i][1] [i] b i 1 int(b[i][1])-a[1] int(b[i][1]) int b[i][1] [i] b i 1 a[1] a 1 time+=a[1] time a[1] a 1 b.append(b.pop(i)) b.append b append b.pop(i) b.pop b pop i b=[] [] b cnt=0 0 cnt a=input().split() input().split() a i=0 0 i a=[int(i) for i in a] [int(i) for i in a] a time+=int(b[i][1]) int(b[i][1]) time time=0 0 time cnt+=int(b[i][1]) int(b[i][1]) cnt time+=a[1] a[1] time
a=input().split()
a=[int(i) for i in a]
b=[]
cnt=0
time=0
for i in range(a[0]):
  b.append(input().split())
  cnt+=int(b[i][1])
i=0
while cnt!=time:
  if int(b[i][1])<=a[1]:
    time+=int(b[i][1])
    print(b[i][0],time)
    b.pop(0)
  else: 
    b[i][1]=int(b[i][1])-a[1]
    time+=a[1]
    b.append(b.pop(i))
    
