import sys
from collections import deque
s=sys.stdin.readlines()
_,q=map(int,s[0].split())
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t) import sys sys from collections import deque s=sys.stdin.readlines() s sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines _,q=map(int,s[0].split()) _ map(int,s[0].split()) map int s[0].split() [0].split [0] s 0 split q f=lambda x,y:(x,int(y)) f lambda x,y:(x,int(y)) (x,int(y)) x int(y) int y x y d=deque(f(*e.split())for e in s[1:]) d deque(f(*e.split())for e in s[1:]) deque f(*e.split()) f *e.split() e.split() e.split e split t=0 t 0 while d:
 k,v=d.popleft()
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t) d k,v=d.popleft() k d.popleft() d.popleft d popleft v if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t) v>q v q v-=q v q t+=q t q d.append([k,v]) d.append d append [k,v] k v t+=v t v print(k,t) print k t v=d.popleft() d.popleft() v _,q=map(int,s[0].split()) map(int,s[0].split()) _ t+=q q t t=0 0 t q=map(int,s[0].split()) map(int,s[0].split()) q t+=v v t s=sys.stdin.readlines() sys.stdin.readlines() s v-=q q v k,v=d.popleft() d.popleft() k d=deque(f(*e.split())for e in s[1:]) deque(f(*e.split())for e in s[1:]) d f=lambda x,y:(x,int(y)) lambda x,y:(x,int(y)) f
import sys
from collections import deque
s=sys.stdin.readlines()
_,q=map(int,s[0].split())
f=lambda x,y:(x,int(y))
d=deque(f(*e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft()
 if v>q:
  v-=q
  t+=q
  d.append([k,v])
 else:
  t+=v
  print(k,t)
