# -*- coding: utf-8 -*-
"""
Created on Tue Jun 20 20:19:33 2017

@author: syaga
"""

if __name__ == "__main__":
    n, q = map(int, input().split())
    a = []
    for i in range(n):
        b = input().split()
        b[1] = int(b[1])
        a.append(b)
    ans = []
    time = 0
    while len(a) != 0:
        x = a.pop(0)
        if x[1] <= q:
            time += x[1]
            ans.append([x[0], time])
        else:
            x[1] -= q
            time += q
            a.append(x)
    for i in ans:
        print(" ".join(map(str, i))) """
Created on Tue Jun 20 20:19:33 2017

@author: syaga
""" if __name__ == "__main__":
    n, q = map(int, input().split())
    a = []
    for i in range(n):
        b = input().split()
        b[1] = int(b[1])
        a.append(b)
    ans = []
    time = 0
    while len(a) != 0:
        x = a.pop(0)
        if x[1] <= q:
            time += x[1]
            ans.append([x[0], time])
        else:
            x[1] -= q
            time += q
            a.append(x)
    for i in ans:
        print(" ".join(map(str, i))) __name__ == "__main__" __name__ "__main__" n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q a = [] a [] for i in range(n):
        b = input().split()
        b[1] = int(b[1])
        a.append(b)
     i range(n) range n b = input().split() b input().split() ().split () input split b[1] = int(b[1]) b[1] b 1 int(b[1]) int b[1] b 1 a.append(b) a.append a append b ans = [] ans [] time = 0 time 0 while len(a) != 0:
        x = a.pop(0)
        if x[1] <= q:
            time += x[1]
            ans.append([x[0], time])
        else:
            x[1] -= q
            time += q
            a.append(x)
     len(a) != 0 len(a) len a 0 x = a.pop(0) x a.pop(0) a.pop a pop 0 if x[1] <= q:
            time += x[1]
            ans.append([x[0], time])
        else:
            x[1] -= q
            time += q
            a.append(x)
     x[1] <= q x[1] x 1 q time += x[1] time x[1] x 1 ans.append([x[0], time]) ans.append ans append [x[0], time] x[0] x 0 time x[1] -= q x[1] x 1 q time += q time q a.append(x) a.append a append x for i in ans:
        print(" ".join(map(str, i))) i ans print(" ".join(map(str, i))) print " ".join(map(str, i)) " ".join " " join map(str, i) map str i b = input().split() input().split() b q = map(int, input().split()) map(int, input().split()) q ans = [] [] ans time = 0 0 time x = a.pop(0) a.pop(0) x time += q q time n, q = map(int, input().split()) map(int, input().split()) n time += x[1] x[1] time a = [] [] a
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 20 20:19:33 2017

@author: syaga
"""

if __name__ == "__main__":
    n, q = map(int, input().split())
    a = []
    for i in range(n):
        b = input().split()
        b[1] = int(b[1])
        a.append(b)
    ans = []
    time = 0
    while len(a) != 0:
        x = a.pop(0)
        if x[1] <= q:
            time += x[1]
            ans.append([x[0], time])
        else:
            x[1] -= q
            time += q
            a.append(x)
    for i in ans:
        print(" ".join(map(str, i)))