def fn(x):
    return [x[0], int(x[1])]

N, q = map(int, input().split())
name_time = list(map(fn, [ input().split() for n in range(N) ]))
sec = 0; finish =[];

while True:
    if len(name_time) == 0:
        break
    elif name_time[0][1] > q:
        sec += q
        name_time[0][1] -= q
        name_time.append(name_time.pop(0))
    else:
        sec += name_time[0][1]
        finish.append([name_time.pop(0)[0],sec])
for f in finish:
    print(*f)
 def fn(x):
    return [x[0], int(x[1])] fn return [x[0], int(x[1])] [x[0], int(x[1])] x[0] x 0 int(x[1]) int x[1] x 1 x x N, q = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split q input().split() for n in range(N) for n in range(N) n range(N) range N for n in range(N) input().split() ().split () input split name_time = list(map(fn, [ input().split() for n in range(N) ])) name_time list(map(fn, [ input().split() for n in range(N) ])) list map(fn, [ input().split() for n in range(N) ]) map fn [ input().split() for n in range(N) ] sec = 0 sec 0 finish =[] finish [] while True:
    if len(name_time) == 0:
        break
    elif name_time[0][1] > q:
        sec += q
        name_time[0][1] -= q
        name_time.append(name_time.pop(0))
    else:
        sec += name_time[0][1]
        finish.append([name_time.pop(0)[0],sec]) True if len(name_time) == 0:
        break
    elif name_time[0][1] > q:
        sec += q
        name_time[0][1] -= q
        name_time.append(name_time.pop(0))
    else:
        sec += name_time[0][1]
        finish.append([name_time.pop(0)[0],sec]) len(name_time) == 0 len(name_time) len name_time 0 break elif name_time[0][1] > q:
        sec += q
        name_time[0][1] -= q
        name_time.append(name_time.pop(0))
     name_time[0][1] > q name_time[0][1] [0] name_time 0 1 q sec += q sec q name_time[0][1] -= q name_time[0][1] [0] name_time 0 1 q name_time.append(name_time.pop(0)) name_time.append name_time append name_time.pop(0) name_time.pop name_time pop 0 sec += name_time[0][1] sec name_time[0][1] [0] name_time 0 1 finish.append([name_time.pop(0)[0],sec]) finish.append finish append [name_time.pop(0)[0],sec] name_time.pop(0)[0] name_time.pop(0) name_time.pop name_time pop 0 0 sec for f in finish:
    print(*f) f finish print(*f) print *f f def fn(x):
    return [x[0], int(x[1])] def fn(x):
    return [x[0], int(x[1])] fn sec = 0 0 sec name_time = list(map(fn, [ input().split() for n in range(N) ])) list(map(fn, [ input().split() for n in range(N) ])) name_time sec += q q sec finish =[] [] finish sec += name_time[0][1] name_time[0][1] sec N, q = map(int, input().split()) map(int, input().split()) N q = map(int, input().split()) map(int, input().split()) q
def fn(x):
    return [x[0], int(x[1])]

N, q = map(int, input().split())
name_time = list(map(fn, [ input().split() for n in range(N) ]))
sec = 0; finish =[];

while True:
    if len(name_time) == 0:
        break
    elif name_time[0][1] > q:
        sec += q
        name_time[0][1] -= q
        name_time.append(name_time.pop(0))
    else:
        sec += name_time[0][1]
        finish.append([name_time.pop(0)[0],sec])
for f in finish:
    print(*f)

