import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    }
} Main public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    } main {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    } Scanner s=new Scanner(System.in); s new Scanner(System.in) int n=s.nextInt(); n s.nextInt() s.nextInt s int q=s.nextInt(); q s.nextInt() s.nextInt s String name[]=new String[n+1]; name new String[n+1] n+1 n 1 int time[]=new int[n+1]; time new int[n+1] n+1 n 1 for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            name[i]=s.next();
            time[i]=s.nextInt();
        } {
            name[i]=s.next();
            time[i]=s.nextInt();
        } name[i]=s.next() name[i] name i s.next() s.next s time[i]=s.nextInt() time[i] time i s.nextInt() s.nextInt s int total=0 total 0 cnt=n cnt n now=0 now 0 next=0; next 0 while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        } cnt!=0 cnt 0 {
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        } if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            } time[now]>0 time[now] time now 0 {
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            } time[now]-=q time[now] time now q if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                } time[now]<=0 time[now] time now 0 {
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                } cnt-- cnt total+=time[now]+q total time[now]+q time[now] time now q System.out.println(name[now]+" "+total) System.out.println System.out System System.out name[now]+" "+total name[now]+" "+total name[now] name now " " total {
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                } total+=q total q next=now+cnt next now+cnt now cnt if(next>n) next-=(n+1); next>n next n next-=(n+1) next (n+1) n 1 name[next]=name[now] name[next] name next name[now] name now time[next]=time[now] time[next] time next time[now] time now time[now]=0 time[now] time now 0 now++ now if(now>n) now-=(n+1); now>n now n now-=(n+1) now (n+1) n 1 String[] args args public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int q=s.nextInt();
        String name[]=new String[n+1];
        int time[]=new int[n+1];
        for(int i=0;i<n;i++){
            name[i]=s.next();
            time[i]=s.nextInt();
        }
        int total=0,cnt=n,now=0,next=0;
        while(cnt!=0){
            if(time[now]>0){
                time[now]-=q;
                if(time[now]<=0){
                    cnt--;
                    total+=time[now]+q;
                    System.out.println(name[now]+" "+total);
                }else{
                    total+=q;
                    next=now+cnt;
                    if(next>n) next-=(n+1);
                    name[next]=name[now];
                    time[next]=time[now];
                }
                time[now]=0;
            }
            now++;
            if(now>n) now-=(n+1);
        }
    }
}
