from collections import deque
import sys

def main():
    n, q = map(int,raw_input().split())
    Q = deque([])
    for i in xrange(n):
        a = raw_input().split()
        a[1] = int(a[1])
        Q.append(a)
    
    elaps = 0
    while len(Q) > 0:
        u = Q.popleft()
        a = min(u[1], q)
        u[1] -= a
        elaps += a
        if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
    return 0

main() from collections import deque import sys sys def main():
    n, q = map(int,raw_input().split())
    Q = deque([])
    for i in xrange(n):
        a = raw_input().split()
        a[1] = int(a[1])
        Q.append(a)
    
    elaps = 0
    while len(Q) > 0:
        u = Q.popleft()
        a = min(u[1], q)
        u[1] -= a
        elaps += a
        if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
    return 0 main n, q = map(int,raw_input().split()) n map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split q Q = deque([]) Q deque([]) deque [] for i in xrange(n):
        a = raw_input().split()
        a[1] = int(a[1])
        Q.append(a)
    
     i xrange(n) xrange n a = raw_input().split() a raw_input().split() ().split () raw_input split a[1] = int(a[1]) a[1] a 1 int(a[1]) int a[1] a 1 Q.append(a) Q.append Q append a elaps = 0 elaps 0 while len(Q) > 0:
        u = Q.popleft()
        a = min(u[1], q)
        u[1] -= a
        elaps += a
        if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
     len(Q) > 0 len(Q) len Q 0 u = Q.popleft() u Q.popleft() Q.popleft Q popleft a = min(u[1], q) a min(u[1], q) min u[1] u 1 q u[1] -= a u[1] u 1 a elaps += a elaps a if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
     u[1] > 0 u[1] u 1 0 Q.append(u) Q.append Q append u print u[0] u 0 elaps return 0 0 main() main def main():
    n, q = map(int,raw_input().split())
    Q = deque([])
    for i in xrange(n):
        a = raw_input().split()
        a[1] = int(a[1])
        Q.append(a)
    
    elaps = 0
    while len(Q) > 0:
        u = Q.popleft()
        a = min(u[1], q)
        u[1] -= a
        elaps += a
        if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
    return 0 def main():
    n, q = map(int,raw_input().split())
    Q = deque([])
    for i in xrange(n):
        a = raw_input().split()
        a[1] = int(a[1])
        Q.append(a)
    
    elaps = 0
    while len(Q) > 0:
        u = Q.popleft()
        a = min(u[1], q)
        u[1] -= a
        elaps += a
        if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
    return 0 main
from collections import deque
import sys

def main():
    n, q = map(int,raw_input().split())
    Q = deque([])
    for i in xrange(n):
        a = raw_input().split()
        a[1] = int(a[1])
        Q.append(a)
    
    elaps = 0
    while len(Q) > 0:
        u = Q.popleft()
        a = min(u[1], q)
        u[1] -= a
        elaps += a
        if u[1] > 0:
            Q.append(u)
        else:
            print u[0], elaps
    return 0

main()