import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
d=deque(list(e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft();v=int(v)
 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 d=deque(list(e.split())for e in s[1:]) d deque(list(e.split())for e in s[1:]) deque list(e.split()) list e.split() e.split e split t=0 t 0 while d:
 k,v=d.popleft();v=int(v)
 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 v=int(v) v int(v) int v if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;print(k,t) v>q v q k,v=d.popleft() d.popleft() k q=int(s[0].split()[1]) int(s[0].split()[1]) q v=int(v) int(v) v v=d.popleft() d.popleft() v s=sys.stdin.readlines() sys.stdin.readlines() s d=deque(list(e.split())for e in s[1:]) deque(list(e.split())for e in s[1:]) d t=0 0 t
import sys
from collections import deque
s=sys.stdin.readlines()
q=int(s[0].split()[1])
d=deque(list(e.split())for e in s[1:])
t=0
while d:
 k,v=d.popleft();v=int(v)
 if v>q:v-=q;t+=q;d.append([k,v])
 else:t+=v;print(k,t)
