if __name__ == "__main__":
      S = (input()).split()
      n = int(S[0])
      q = int(S[1])
      head = 0
      tail = n-1
      que = []
      runtime = 0
      fin = []

      for i in range(0, n):
            que.append((input()).split())

      while head <= tail:
            nowjob = que[head]
            jobtime = int(nowjob[1])
            if jobtime > q :
                  jobtime = jobtime -q
                  jobname = nowjob[0]
                  que.append([jobname, jobtime])
                  runtime = runtime + q
                  head = head + 1
                  tail = tail + 1
            else :
                  runtime = runtime + jobtime
                  fin.append([(que[head])[0], runtime])
                  head = head + 1
      for i in range(0,n):
            print("{} {}".format((fin[i])[0], (fin[i])[1])) if __name__ == "__main__":
      S = (input()).split()
      n = int(S[0])
      q = int(S[1])
      head = 0
      tail = n-1
      que = []
      runtime = 0
      fin = []

      for i in range(0, n):
            que.append((input()).split())

      while head <= tail:
            nowjob = que[head]
            jobtime = int(nowjob[1])
            if jobtime > q :
                  jobtime = jobtime -q
                  jobname = nowjob[0]
                  que.append([jobname, jobtime])
                  runtime = runtime + q
                  head = head + 1
                  tail = tail + 1
            else :
                  runtime = runtime + jobtime
                  fin.append([(que[head])[0], runtime])
                  head = head + 1
      for i in range(0,n):
            print("{} {}".format((fin[i])[0], (fin[i])[1])) __name__ == "__main__" __name__ "__main__" S = (input()).split() S (input()).split() input()).split input() input split n = int(S[0]) n int(S[0]) int S[0] S 0 q = int(S[1]) q int(S[1]) int S[1] S 1 head = 0 head 0 tail = n-1 tail n-1 n 1 que = [] que [] runtime = 0 runtime 0 fin = [] fin [] for i in range(0, n):
            que.append((input()).split())

       i range(0, n) range 0 n que.append((input()).split()) que.append que append (input()).split() input()).split input() input split while head <= tail:
            nowjob = que[head]
            jobtime = int(nowjob[1])
            if jobtime > q :
                  jobtime = jobtime -q
                  jobname = nowjob[0]
                  que.append([jobname, jobtime])
                  runtime = runtime + q
                  head = head + 1
                  tail = tail + 1
            else :
                  runtime = runtime + jobtime
                  fin.append([(que[head])[0], runtime])
                  head = head + 1
       head <= tail head tail nowjob = que[head] nowjob que[head] que head jobtime = int(nowjob[1]) jobtime int(nowjob[1]) int nowjob[1] nowjob 1 if jobtime > q :
                  jobtime = jobtime -q
                  jobname = nowjob[0]
                  que.append([jobname, jobtime])
                  runtime = runtime + q
                  head = head + 1
                  tail = tail + 1
            else :
                  runtime = runtime + jobtime
                  fin.append([(que[head])[0], runtime])
                  head = head + 1
       jobtime > q jobtime q jobtime = jobtime -q jobtime jobtime -q jobtime q jobname = nowjob[0] jobname nowjob[0] nowjob 0 que.append([jobname, jobtime]) que.append que append [jobname, jobtime] jobname jobtime runtime = runtime + q runtime runtime + q runtime q head = head + 1 head head + 1 head 1 tail = tail + 1 tail tail + 1 tail 1 runtime = runtime + jobtime runtime runtime + jobtime runtime jobtime fin.append([(que[head])[0], runtime]) fin.append fin append [(que[head])[0], runtime] (que[head])[0] que[head] que head 0 runtime head = head + 1 head head + 1 head 1 for i in range(0,n):
            print("{} {}".format((fin[i])[0], (fin[i])[1])) i range(0,n) range 0 n print("{} {}".format((fin[i])[0], (fin[i])[1])) print "{} {}".format((fin[i])[0], (fin[i])[1]) "{} {}".format "{} {}" format (fin[i])[0] fin[i] fin i 0 (fin[i])[1] fin[i] fin i 1 jobtime = jobtime -q jobtime -q jobtime jobname = nowjob[0] nowjob[0] jobname nowjob = que[head] que[head] nowjob S = (input()).split() (input()).split() S q = int(S[1]) int(S[1]) q runtime = runtime + q runtime + q runtime tail = tail + 1 tail + 1 tail head = head + 1 head + 1 head que = [] [] que n = int(S[0]) int(S[0]) n tail = n-1 n-1 tail head = 0 0 head fin = [] [] fin jobtime = int(nowjob[1]) int(nowjob[1]) jobtime runtime = runtime + jobtime runtime + jobtime runtime runtime = 0 0 runtime head = head + 1 head + 1 head
if __name__ == "__main__":
      S = (input()).split()
      n = int(S[0])
      q = int(S[1])
      head = 0
      tail = n-1
      que = []
      runtime = 0
      fin = []

      for i in range(0, n):
            que.append((input()).split())

      while head <= tail:
            nowjob = que[head]
            jobtime = int(nowjob[1])
            if jobtime > q :
                  jobtime = jobtime -q
                  jobname = nowjob[0]
                  que.append([jobname, jobtime])
                  runtime = runtime + q
                  head = head + 1
                  tail = tail + 1
            else :
                  runtime = runtime + jobtime
                  fin.append([(que[head])[0], runtime])
                  head = head + 1
      for i in range(0,n):
            print("{} {}".format((fin[i])[0], (fin[i])[1]))