import collections
q=collections.deque()
n,m=map(int,input().split())
for i in range(n):
  a,b=input().split()
  b=int(b)
  q.append([a,b])
t=0
while len(q)!=0:
  n=q.popleft()
  if n[1]<=m:
    t+=n[1]
    print(n[0],str(t))
  else:
    t+=m
    n[1]-=m
    q.append(n) import collections collections q=collections.deque() q collections.deque() collections.deque collections deque n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m for i in range(n):
  a,b=input().split()
  b=int(b)
  q.append([a,b]) i range(n) range n a,b=input().split() a input().split() ().split () input split b b=int(b) b int(b) int b q.append([a,b]) q.append q append [a,b] a b t=0 t 0 while len(q)!=0:
  n=q.popleft()
  if n[1]<=m:
    t+=n[1]
    print(n[0],str(t))
  else:
    t+=m
    n[1]-=m
    q.append(n) len(q)!=0 len(q) len q 0 n=q.popleft() n q.popleft() q.popleft q popleft if n[1]<=m:
    t+=n[1]
    print(n[0],str(t))
  else:
    t+=m
    n[1]-=m
    q.append(n) n[1]<=m n[1] n 1 m t+=n[1] t n[1] n 1 print(n[0],str(t)) print n[0] n 0 str(t) str t t+=m t m n[1]-=m n[1] n 1 m q.append(n) q.append q append n n=q.popleft() q.popleft() n b=int(b) int(b) b t=0 0 t b=input().split() input().split() b m=map(int,input().split()) map(int,input().split()) m q=collections.deque() collections.deque() q n,m=map(int,input().split()) map(int,input().split()) n t+=n[1] n[1] t a,b=input().split() input().split() a t+=m m t
import collections
q=collections.deque()
n,m=map(int,input().split())
for i in range(n):
  a,b=input().split()
  b=int(b)
  q.append([a,b])
t=0
while len(q)!=0:
  n=q.popleft()
  if n[1]<=m:
    t+=n[1]
    print(n[0],str(t))
  else:
    t+=m
    n[1]-=m
    q.append(n)
