Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
p=[]
for _ in[0]*n:
 s,k=input().split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  a=p[i]
  if b[i]:
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,q=map(int,input().split())
p=[]
for e in sys.stdin:
 s,k=e.split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  a=p[i]
  if b[i]:
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
n,q=map(int,input().split())
p=[]
for e in sys.stdin:
 s,k=e.split()
 p+=[[s,int(k)]]
b=[1]*n
t=0
while sum(b):
 for i in range(n):
  if b[i]:
   a=p[i]
   if a[1]>q:a[1]-=q;t+=q
   else:b[i]=0;t+=a[1];print(a[0],t)


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
m,p=[0],[0]
for _ in[0]*n:
 s,k=input().split()
 m+=[s]
 p+=[int(k)]
b=list(range(n+1))
t=0
while sum(b):
 for i in b:
  if p[i]>q:p[i]-=q;t+=q
  elif m[i]:b[i]=0;t+=p[i];print(m[i],t)


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
n,q=map(int,input().split())
d=deque(map(lambda x,y:[x,int(y)],sys.stdin))
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)


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
def m():
 s=sys.stdin.readlines()
 q=int(s[0].split()[1])
 f=lambda x,y:(x,int(y))
 d=deque(map(*e.split())for e in s[1:])
 t,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d+[[k,v]]
  else:t+=v;a+=[f'{k} {t}\n']
 print(a[:-1])
m()


Fixed submission:
import sys
from collections import deque
def m():
 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,a=0,[]
 while d:
  k,v=d.popleft()
  if v>q:v-=q;t+=q;d.append([k,v])
  else:t+=v;a+=[f'{k} {t}']
 print('\n'.join(a))
if'__main__'==__name__:m()