nq = str(input()).split()
n = int(nq[0])
q = int(nq[1])
p = [str(input()).split() for i in range(n)]
p = [(str(i[0]), int(i[1])) for i in p]
ans = []
time = 0
while len(p) != 0:
    t = p.pop(0)
    if t[1] > q:
        #p = [(s[0], s[1], s[2]+q) for s in p]
        time += q
        p.append((t[0], t[1]-q))
    elif t[1] <= q:
        #p = [(s[0], s[1], s[2]+t[1]) for s in p]
        ans.append((t[0], t[1]+time))
        time += t[1]
for t in ans:
    print('{0} {1}'.format(t[0], t[1])) nq = str(input()).split() nq str(input()).split() (input()).split (input()) str input() input split n = int(nq[0]) n int(nq[0]) int nq[0] nq 0 q = int(nq[1]) q int(nq[1]) int nq[1] nq 1 str(input()).split() for i in range(n) for i in range(n) i range(n) range n for i in range(n) str(input()).split() (input()).split (input()) str input() input split p = [str(input()).split() for i in range(n)] p [str(input()).split() for i in range(n)] (str(i[0]), int(i[1])) for i in p for i in p i p for i in p (str(i[0]), int(i[1])) str(i[0]) str i[0] i 0 int(i[1]) int i[1] i 1 p = [(str(i[0]), int(i[1])) for i in p] p [(str(i[0]), int(i[1])) for i in p] ans = [] ans [] time = 0 time 0 while len(p) != 0:
    t = p.pop(0)
    if t[1] > q:
        #p = [(s[0], s[1], s[2]+q) for s in p]
        time += q
        p.append((t[0], t[1]-q))
    elif t[1] <= q:
        #p = [(s[0], s[1], s[2]+t[1]) for s in p]
        ans.append((t[0], t[1]+time))
        time += t[1] len(p) != 0 len(p) len p 0 t = p.pop(0) t p.pop(0) p.pop p pop 0 if t[1] > q:
        #p = [(s[0], s[1], s[2]+q) for s in p]
        time += q
        p.append((t[0], t[1]-q))
    elif t[1] <= q:
        #p = [(s[0], s[1], s[2]+t[1]) for s in p]
        ans.append((t[0], t[1]+time))
        time += t[1] t[1] > q t[1] t 1 q time += q time q p.append((t[0], t[1]-q)) p.append p append (t[0], t[1]-q) t[0] t 0 t[1]-q t[1] t 1 q elif t[1] <= q:
        #p = [(s[0], s[1], s[2]+t[1]) for s in p]
        ans.append((t[0], t[1]+time))
        time += t[1] t[1] <= q t[1] t 1 q ans.append((t[0], t[1]+time)) ans.append ans append (t[0], t[1]+time) t[0] t 0 t[1]+time t[1] t 1 time time += t[1] time t[1] t 1 for t in ans:
    print('{0} {1}'.format(t[0], t[1])) t ans print('{0} {1}'.format(t[0], t[1])) print '{0} {1}'.format(t[0], t[1]) '{0} {1}'.format '{0} {1}' format t[0] t 0 t[1] t 1 t = p.pop(0) p.pop(0) t nq = str(input()).split() str(input()).split() nq q = int(nq[1]) int(nq[1]) q p = [str(input()).split() for i in range(n)] [str(input()).split() for i in range(n)] p time += q q time time += t[1] t[1] time time = 0 0 time n = int(nq[0]) int(nq[0]) n p = [(str(i[0]), int(i[1])) for i in p] [(str(i[0]), int(i[1])) for i in p] p ans = [] [] ans
nq = str(input()).split()
n = int(nq[0])
q = int(nq[1])
p = [str(input()).split() for i in range(n)]
p = [(str(i[0]), int(i[1])) for i in p]
ans = []
time = 0
while len(p) != 0:
    t = p.pop(0)
    if t[1] > q:
        #p = [(s[0], s[1], s[2]+q) for s in p]
        time += q
        p.append((t[0], t[1]-q))
    elif t[1] <= q:
        #p = [(s[0], s[1], s[2]+t[1]) for s in p]
        ans.append((t[0], t[1]+time))
        time += t[1]
for t in ans:
    print('{0} {1}'.format(t[0], t[1]))