a = input().split()
n = int(a[0])
q = int(a[1])

N = [] #プロセス名
T1 = [] #必要時間


for i in range(n):
    a = input().split()
    N.append(a[0])
    T1.append(int(a[1]))

t = 0 #経過時間
f = 0 #処理対象
l = len(N)-1 #最後尾

while len(N) > 0:
    if T1[f] <= q: #処理が完了する
        t += T1[f]
        if f == len(N)-1:
            print(N.pop(f), t)
            del T1[f]
            f = 0
        elif f == 0:
            print(N.pop(f), t)
            del T1[f]
            l -= 1
        else:
            print(N.pop(f), t)
            del T1[f]
        
        if len(N) == 0: break

    else: #処理が完了しない
        t += q
        T1[f] -= q

        i = N[f]
        j = T1[f]

        if f+1 == len(N): f = 0
        else: f += 1
        if l+1 == len(N): l = 0
        else: l += 1
        
        N[l] = i
        T1[l] = j a = input().split() a input().split() ().split () input split n = int(a[0]) n int(a[0]) int a[0] a 0 q = int(a[1]) q int(a[1]) int a[1] a 1 N = [] N [] T1 = [] T1 [] for i in range(n):
    a = input().split()
    N.append(a[0])
    T1.append(int(a[1])) i range(n) range n a = input().split() a input().split() ().split () input split N.append(a[0]) N.append N append a[0] a 0 T1.append(int(a[1])) T1.append T1 append int(a[1]) int a[1] a 1 t = 0 t 0 f = 0 f 0 l = len(N)-1 l len(N)-1 len(N) len N 1 while len(N) > 0:
    if T1[f] <= q: #処理が完了する
        t += T1[f]
        if f == len(N)-1:
            print(N.pop(f), t)
            del T1[f]
            f = 0
        elif f == 0:
            print(N.pop(f), t)
            del T1[f]
            l -= 1
        else:
            print(N.pop(f), t)
            del T1[f]
        
        if len(N) == 0: break

    else: #処理が完了しない
        t += q
        T1[f] -= q

        i = N[f]
        j = T1[f]

        if f+1 == len(N): f = 0
        else: f += 1
        if l+1 == len(N): l = 0
        else: l += 1
        
        N[l] = i
        T1[l] = j len(N) > 0 len(N) len N 0 if T1[f] <= q: #処理が完了する
        t += T1[f]
        if f == len(N)-1:
            print(N.pop(f), t)
            del T1[f]
            f = 0
        elif f == 0:
            print(N.pop(f), t)
            del T1[f]
            l -= 1
        else:
            print(N.pop(f), t)
            del T1[f]
        
        if len(N) == 0: break

    else: #処理が完了しない
        t += q
        T1[f] -= q

        i = N[f]
        j = T1[f]

        if f+1 == len(N): f = 0
        else: f += 1
        if l+1 == len(N): l = 0
        else: l += 1
        
        N[l] = i
        T1[l] = j T1[f] <= q T1[f] T1 f q t += T1[f] t T1[f] T1 f if f == len(N)-1:
            print(N.pop(f), t)
            del T1[f]
            f = 0
        elif f == 0:
            print(N.pop(f), t)
            del T1[f]
            l -= 1
        else:
            print(N.pop(f), t)
            del T1[f]
        
         f == len(N)-1 f len(N)-1 len(N) len N 1 print(N.pop(f), t) print N.pop(f) N.pop N pop f t del T1[f] T1[f] T1 f f = 0 f 0 elif f == 0:
            print(N.pop(f), t)
            del T1[f]
            l -= 1
         f == 0 f 0 print(N.pop(f), t) print N.pop(f) N.pop N pop f t del T1[f] T1[f] T1 f l -= 1 l 1 print(N.pop(f), t) print N.pop(f) N.pop N pop f t del T1[f] T1[f] T1 f if len(N) == 0: break

     len(N) == 0 len(N) len N 0 t += q t q T1[f] -= q T1[f] T1 f q i = N[f] i N[f] N f j = T1[f] j T1[f] T1 f if f+1 == len(N): f = 0
        else: f += 1
         f+1 == len(N) f+1 f 1 len(N) len N if l+1 == len(N): l = 0
        else: l += 1
        
         l+1 == len(N) l+1 l 1 len(N) len N N[l] = i N[l] N l i T1[l] = j T1[l] T1 l j a = input().split() input().split() a n = int(a[0]) int(a[0]) n f = 0 0 f i = N[f] N[f] i t += q q t q = int(a[1]) int(a[1]) q a = input().split() input().split() a t += T1[f] T1[f] t j = T1[f] T1[f] j l = len(N)-1 len(N)-1 l T1 = [] [] T1 t = 0 0 t l -= 1 1 l N = [] [] N f = 0 0 f
a = input().split()
n = int(a[0])
q = int(a[1])

N = [] #プロセス名
T1 = [] #必要時間


for i in range(n):
    a = input().split()
    N.append(a[0])
    T1.append(int(a[1]))

t = 0 #経過時間
f = 0 #処理対象
l = len(N)-1 #最後尾

while len(N) > 0:
    if T1[f] <= q: #処理が完了する
        t += T1[f]
        if f == len(N)-1:
            print(N.pop(f), t)
            del T1[f]
            f = 0
        elif f == 0:
            print(N.pop(f), t)
            del T1[f]
            l -= 1
        else:
            print(N.pop(f), t)
            del T1[f]
        
        if len(N) == 0: break

    else: #処理が完了しない
        t += q
        T1[f] -= q

        i = N[f]
        j = T1[f]

        if f+1 == len(N): f = 0
        else: f += 1
        if l+1 == len(N): l = 0
        else: l += 1
        
        N[l] = i
        T1[l] = j
