#queue
n,q=(int(i) for i in input().split())
nl=[]
t=[]
et=0
for i in range(n):
    na,ti=(j for j in input().split())
 #   print(t)
    nl.append(na)
    t.append(int(ti))
i=0
while len(nl)>0:
    t[i]-=q
    et+=q
 #   print(t)
    if t[i]<=0:
        et+=t[i]
        print(nl[i]+" "+str(et))
        nl.pop(i)
        t.pop(i)
        i-=1
    i+=1
    if i>=len(nl):
        i=0 int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i n,q=(int(i) for i in input().split()) n (int(i) for i in input().split()) q nl=[] nl [] t=[] t [] et=0 et 0 for i in range(n):
    na,ti=(j for j in input().split())
 #   print(t)
    nl.append(na)
    t.append(int(ti)) i range(n) range n j for j in input().split() for j in input().split() j input().split() ().split () input split for j in input().split() j na,ti=(j for j in input().split()) na (j for j in input().split()) ti nl.append(na) nl.append nl append na t.append(int(ti)) t.append t append int(ti) int ti i=0 i 0 while len(nl)>0:
    t[i]-=q
    et+=q
 #   print(t)
    if t[i]<=0:
        et+=t[i]
        print(nl[i]+" "+str(et))
        nl.pop(i)
        t.pop(i)
        i-=1
    i+=1
    if i>=len(nl):
        i=0 len(nl)>0 len(nl) len nl 0 t[i]-=q t[i] t i q et+=q et q if t[i]<=0:
        et+=t[i]
        print(nl[i]+" "+str(et))
        nl.pop(i)
        t.pop(i)
        i-=1
     t[i]<=0 t[i] t i 0 et+=t[i] et t[i] t i print(nl[i]+" "+str(et)) print nl[i]+" "+str(et) nl[i]+" " nl[i] nl i " " str(et) str et nl.pop(i) nl.pop nl pop i t.pop(i) t.pop t pop i i-=1 i 1 i+=1 i 1 if i>=len(nl):
        i=0 i>=len(nl) i len(nl) len nl i=0 i 0 et=0 0 et na,ti=(j for j in input().split()) (j for j in input().split()) na i=0 0 i i+=1 1 i ti=(j for j in input().split()) (j for j in input().split()) ti et+=t[i] t[i] et i=0 0 i i-=1 1 i t=[] [] t et+=q q et n,q=(int(i) for i in input().split()) (int(i) for i in input().split()) n nl=[] [] nl q=(int(i) for i in input().split()) (int(i) for i in input().split()) q
#queue
n,q=(int(i) for i in input().split())
nl=[]
t=[]
et=0
for i in range(n):
    na,ti=(j for j in input().split())
 #   print(t)
    nl.append(na)
    t.append(int(ti))
i=0
while len(nl)>0:
    t[i]-=q
    et+=q
 #   print(t)
    if t[i]<=0:
        et+=t[i]
        print(nl[i]+" "+str(et))
        nl.pop(i)
        t.pop(i)
        i-=1
    i+=1
    if i>=len(nl):
        i=0