import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
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=int(s[0].split()[1]) q int(s[0].split()[1]) int s[0].split()[1] [0].split() [0].split [0] s 0 split 1 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 s=sys.stdin.readlines() sys.stdin.readlines() s v=d.popleft() d.popleft() v q=int(s[0].split()[1]) int(s[0].split()[1]) q d=deque(f(*e.split())for e in s[1:]) deque(f(*e.split())for e in s[1:]) d t=0 0 t f=lambda x,y:(x,int(y)) lambda x,y:(x,int(y)) f k,v=d.popleft() d.popleft() k
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
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)
