N_str, q_str = raw_input().split()
N = int(N_str)
q = int(q_str)

A = []
B = []

for i in range(N):
    a = raw_input().split()
    A.append([a[0], int(a[1])])

total_time = 0
while A:
    name, time = A.pop(0)
    if time <= q:
        total_time += time 
        B.append("%s %d" % (name, total_time))
    else:
        time -= q
        A.append([name, time])
        total_time += q
print '\n'.join(B) N_str, q_str = raw_input().split() N_str raw_input().split() ().split () raw_input split q_str N = int(N_str) N int(N_str) int N_str q = int(q_str) q int(q_str) int q_str A = [] A [] B = [] B [] for i in range(N):
    a = raw_input().split()
    A.append([a[0], int(a[1])]) i range(N) range N a = raw_input().split() a raw_input().split() ().split () raw_input split A.append([a[0], int(a[1])]) A.append A append [a[0], int(a[1])] a[0] a 0 int(a[1]) int a[1] a 1 total_time = 0 total_time 0 while A:
    name, time = A.pop(0)
    if time <= q:
        total_time += time 
        B.append("%s %d" % (name, total_time))
    else:
        time -= q
        A.append([name, time])
        total_time += q A name, time = A.pop(0) name A.pop(0) A.pop A pop 0 time if time <= q:
        total_time += time 
        B.append("%s %d" % (name, total_time))
    else:
        time -= q
        A.append([name, time])
        total_time += q time <= q time q total_time += time total_time time B.append("%s %d" % (name, total_time)) B.append B append "%s %d" % (name, total_time) "%s %d" (name, total_time) name total_time time -= q time q A.append([name, time]) A.append A append [name, time] name time total_time += q total_time q print '\n'.join(B) '\n'.join '\n' join B A = [] [] A total_time += time time total_time total_time = 0 0 total_time q_str = raw_input().split() raw_input().split() q_str N_str, q_str = raw_input().split() raw_input().split() N_str total_time += q q total_time name, time = A.pop(0) A.pop(0) name q = int(q_str) int(q_str) q time -= q q time a = raw_input().split() raw_input().split() a B = [] [] B N = int(N_str) int(N_str) N time = A.pop(0) A.pop(0) time
N_str, q_str = raw_input().split()
N = int(N_str)
q = int(q_str)

A = []
B = []

for i in range(N):
    a = raw_input().split()
    A.append([a[0], int(a[1])])

total_time = 0
while A:
    name, time = A.pop(0)
    if time <= q:
        total_time += time 
        B.append("%s %d" % (name, total_time))
    else:
        time -= q
        A.append([name, time])
        total_time += q
print '\n'.join(B)