output_description: For each process, prints its name and the time the process finished in order.
input_description: _n_ _q_  
  _name 1 time1_  
  _name 2 time2_  
  ...  
  _name n timen_  
  
  In the first line the number of processes _n_ and the quantum _q_ are given
  separated by a single space.
  
  In the following _n_ lines, names and times for the _n_ processes are given.
  _name i_ and _time i_ are separated by a single space.
attempt: class ArrayDeque:
      def __init__(self):
          self.a_size = 1
          self.a = [None]
          self.n = 0
          self.head = 0
          self.tail = 0
  
      def __bool__(self):
          return self.n != 0
  
      def _resize(self):
          new_a = [None] * ((self.n + 1) << 1)
          for i in range(self.n):
              new_a[i] = self.a[(self.head + i) & (self.a_size - 1)]
          self.a = new_a
          self.a_size = (self.n + 1) << 1
          self.head = 0
          self.tail = self.n
  
      def append(self, val):
          if self.n == self.a_size - 1:
              self._resize()
          self.a[self.tail] = val
          self.tail = (self.tail + 1) & (self.a_size - 1)
          self.n += 1
  
      def appendleft(self, val):
          if self.n == self.a_size - 1:
              self._resize()
          self.head = (self.head - 1) & (self.a_size - 1)
          self.a[self.head] = val
          self.n += 1
  
      def popleft(self):
          if self.n == 0:
              raise IndexError()
          val = self.a[self.head]
          self.head = (self.head + 1) & (self.a_size - 1)
          self.n -= 1
          if self.a_size >= 4 * self.n + 2:
              self._resize()
          return val
  
      def pop(self):
          if self.n == 0:
              raise IndexError()
          self.tail = (self.tail - 1) & (self.a_size - 1)
          val = self.a[self.tail]
          self.n -= 1
          if self.a_size >= 4 * self.n + 2:
              self._resize()
          return val
  
  
  n, q = map(int, input().split())
  info = [input().split() for i in range(n)]
  
  que = ArrayDeque()
  for name, time in info:
      que.append((name, int(time)))
  
  ans_time = 0
  ans = []
  while que:
      name, time = que.popleft()
      if time > q:
          que.append((name, time - q))
          ans_time += q
      else:
          ans_time += time
          ans.append((name, ans_time))
  
  for name, time in ans:
      print(name, time)
  
problem_description: Input
  
  _n_ _q_  
  _name 1 time1_  
  _name 2 time2_  
  ...  
  _name n timen_  
  
  In the first line the number of processes _n_ and the quantum _q_ are given
  separated by a single space.
  
  In the following _n_ lines, names and times for the _n_ processes are given.
  _name i_ and _time i_ are separated by a single space.
samples: [{"input": "5 100\n    p1 150\n    p2 80\n    p3 200\n    p4 350\n    p5 20", "output": "p2 180\n    p5 400\n    p1 450\n    p3 550\n    p4 800"}]