import collections
calc_time = 0
hoge = collections.deque()
num, q = [int(x) for x in input().split()]
for _ in range(num):
    name, t = input().split()
    hoge.append([name, int(t)])
while hoge:
    name, t = hoge.popleft()
    if t - q > 0:
        hoge.append([name, t-q])
        calc_time += q
    elif t == q:
        calc_time += q
        print ('{} {}'.format(name, calc_time))
    elif t - q < 0:
        calc_time += t
        print ('{} {}'.format(name, calc_time)) import collections collections calc_time = 0 calc_time 0 hoge = collections.deque() hoge collections.deque() collections.deque collections deque int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x num, q = [int(x) for x in input().split()] num [int(x) for x in input().split()] q for _ in range(num):
    name, t = input().split()
    hoge.append([name, int(t)]) _ range(num) range num name, t = input().split() name input().split() ().split () input split t hoge.append([name, int(t)]) hoge.append hoge append [name, int(t)] name int(t) int t while hoge:
    name, t = hoge.popleft()
    if t - q > 0:
        hoge.append([name, t-q])
        calc_time += q
    elif t == q:
        calc_time += q
        print ('{} {}'.format(name, calc_time))
    elif t - q < 0:
        calc_time += t
        print ('{} {}'.format(name, calc_time)) hoge name, t = hoge.popleft() name hoge.popleft() hoge.popleft hoge popleft t if t - q > 0:
        hoge.append([name, t-q])
        calc_time += q
    elif t == q:
        calc_time += q
        print ('{} {}'.format(name, calc_time))
    elif t - q < 0:
        calc_time += t
        print ('{} {}'.format(name, calc_time)) t - q > 0 t - q t q 0 hoge.append([name, t-q]) hoge.append hoge append [name, t-q] name t-q t q calc_time += q calc_time q elif t == q:
        calc_time += q
        print ('{} {}'.format(name, calc_time))
     t == q t q calc_time += q calc_time q print ('{} {}'.format(name, calc_time)) print '{} {}'.format(name, calc_time) '{} {}'.format '{} {}' format name calc_time elif t - q < 0:
        calc_time += t
        print ('{} {}'.format(name, calc_time)) t - q < 0 t - q t q 0 calc_time += t calc_time t print ('{} {}'.format(name, calc_time)) print '{} {}'.format(name, calc_time) '{} {}'.format '{} {}' format name calc_time hoge = collections.deque() collections.deque() hoge num, q = [int(x) for x in input().split()] [int(x) for x in input().split()] num calc_time += q q calc_time t = input().split() input().split() t calc_time = 0 0 calc_time name, t = input().split() input().split() name calc_time += q q calc_time q = [int(x) for x in input().split()] [int(x) for x in input().split()] q t = hoge.popleft() hoge.popleft() t calc_time += t t calc_time name, t = hoge.popleft() hoge.popleft() name
import collections
calc_time = 0
hoge = collections.deque()
num, q = [int(x) for x in input().split()]
for _ in range(num):
    name, t = input().split()
    hoge.append([name, int(t)])
while hoge:
    name, t = hoge.popleft()
    if t - q > 0:
        hoge.append([name, t-q])
        calc_time += q
    elif t == q:
        calc_time += q
        print ('{} {}'.format(name, calc_time))
    elif t - q < 0:
        calc_time += t
        print ('{} {}'.format(name, calc_time))
