from collections import deque

process = deque(maxlen=100000)
n, q = [int(x) for x in input().split(' ')]

for i in range(n):
    name, time = input().split(' ')
    process.append([name, int(time)])

total_time = 0

while process:
    p_q = process.popleft()
    if p_q[1] > q:
        total_time += q
        p_q[1] -= q
        process.append(p_q)
    else:
        total_time += p_q[1]
        print('{} {}'.format(p_q[0], total_time)) from collections import deque process = deque(maxlen=100000) process deque(maxlen=100000) deque maxlen=100000 maxlen 100000 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 n, q = [int(x) for x in input().split(' ')] n [int(x) for x in input().split(' ')] q for i in range(n):
    name, time = input().split(' ')
    process.append([name, int(time)]) i range(n) range n name, time = input().split(' ') name input().split(' ') ().split () input split ' ' time process.append([name, int(time)]) process.append process append [name, int(time)] name int(time) int time total_time = 0 total_time 0 while process:
    p_q = process.popleft()
    if p_q[1] > q:
        total_time += q
        p_q[1] -= q
        process.append(p_q)
    else:
        total_time += p_q[1]
        print('{} {}'.format(p_q[0], total_time)) process p_q = process.popleft() p_q process.popleft() process.popleft process popleft if p_q[1] > q:
        total_time += q
        p_q[1] -= q
        process.append(p_q)
    else:
        total_time += p_q[1]
        print('{} {}'.format(p_q[0], total_time)) p_q[1] > q p_q[1] p_q 1 q total_time += q total_time q p_q[1] -= q p_q[1] p_q 1 q process.append(p_q) process.append process append p_q total_time += p_q[1] total_time p_q[1] p_q 1 print('{} {}'.format(p_q[0], total_time)) print '{} {}'.format(p_q[0], total_time) '{} {}'.format '{} {}' format p_q[0] p_q 0 total_time p_q = process.popleft() process.popleft() p_q total_time += p_q[1] p_q[1] total_time total_time += q q total_time name, time = input().split(' ') input().split(' ') name process = deque(maxlen=100000) deque(maxlen=100000) process q = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] q total_time = 0 0 total_time n, q = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] n time = input().split(' ') input().split(' ') time
from collections import deque

process = deque(maxlen=100000)
n, q = [int(x) for x in input().split(' ')]

for i in range(n):
    name, time = input().split(' ')
    process.append([name, int(time)])

total_time = 0

while process:
    p_q = process.popleft()
    if p_q[1] > q:
        total_time += q
        p_q[1] -= q
        process.append(p_q)
    else:
        total_time += p_q[1]
        print('{} {}'.format(p_q[0], total_time))