import sys
n, q = list(map(int, input().split()))

robin = list(map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin))))

t = []
time = 0
while 0 < len(robin):
    r = robin.pop(0)
    remain = r[1]
    if q < remain:
        r[1] = remain - q
        robin.append(r)
        time += q
    else:
        time += remain
        t.append([r[0], time])

for i in t:
    print(' '.join(map(str, i))) import sys sys n, q = list(map(int, input().split())) n list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split q robin = list(map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin)))) robin list(map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin)))) list map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin))) map lambda y: [y[0], int(y[1])] [y[0], int(y[1])] y[0] y 0 int(y[1]) int y[1] y 1 y list(map(lambda x: x.split(), sys.stdin)) list map(lambda x: x.split(), sys.stdin) map lambda x: x.split() x.split() x.split x split x sys.stdin sys stdin t = [] t [] time = 0 time 0 while 0 < len(robin):
    r = robin.pop(0)
    remain = r[1]
    if q < remain:
        r[1] = remain - q
        robin.append(r)
        time += q
    else:
        time += remain
        t.append([r[0], time]) 0 < len(robin) 0 len(robin) len robin r = robin.pop(0) r robin.pop(0) robin.pop robin pop 0 remain = r[1] remain r[1] r 1 if q < remain:
        r[1] = remain - q
        robin.append(r)
        time += q
    else:
        time += remain
        t.append([r[0], time]) q < remain q remain r[1] = remain - q r[1] r 1 remain - q remain q robin.append(r) robin.append robin append r time += q time q time += remain time remain t.append([r[0], time]) t.append t append [r[0], time] r[0] r 0 time for i in t:
    print(' '.join(map(str, i))) i t print(' '.join(map(str, i))) print ' '.join(map(str, i)) ' '.join ' ' join map(str, i) map str i time = 0 0 time time += remain remain time n, q = list(map(int, input().split())) list(map(int, input().split())) n q = list(map(int, input().split())) list(map(int, input().split())) q time += q q time r = robin.pop(0) robin.pop(0) r t = [] [] t robin = list(map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin)))) list(map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin)))) robin remain = r[1] r[1] remain
import sys
n, q = list(map(int, input().split()))

robin = list(map(lambda y: [y[0], int(y[1])], list(map(lambda x: x.split(), sys.stdin))))

t = []
time = 0
while 0 < len(robin):
    r = robin.pop(0)
    remain = r[1]
    if q < remain:
        r[1] = remain - q
        robin.append(r)
        time += q
    else:
        time += remain
        t.append([r[0], time])

for i in t:
    print(' '.join(map(str, i)))