class zGisABmWvmPwebokmbJdisLUWXGFbNTsZBViNmCagYEdkEhCOtoYEQXaHFeejWKVAyyNzjVYaSIF
{
    public class RBlQYfklICOtftnKZOrhMMHqcIHnhNUevjRFhpFekoxMzDpaBHqSgdDZmRsexwyrykMLiqiDcRFu
    {
        public string KGikKmlxEfvttXtArkRxKFqlhkuSgBcploDlsrtBdbnbVrPpUCXEytXXmLpDjnGRIXuHRHuxbWxK {get; set;}
        public int dQGrrjOgrQUqnAdEcpZAVArZDECxpCHKSPDVFzFpYpzuZJBtrZGpbWfBhGZphBhrWPDujtsYCawX {get; set;} 
    }
    static void Main(string[] wmPkkhBFyjwguDONYrQygYFzZKjgKckYWJeFuikMiveDOBOQBENjqyAWGnuEdSWEEfdrSBLHDhPD)
    {
        var PubjPuTfjvhPGglOhuDhaDBJdzxdzvCwlcjmezyRWrAWzJjqvILRONMzxNBUJUfmCZvWffSYvfST = System.Console.ReadLine().Split(' ');
        var UPPWbwXQduMtmpObiAqkPCTohxmkohgHbfkXvjfOvKZfyNMczXhYaddwKagVBOBXUnzrdAIrlgrJ = System.Int32.Parse(PubjPuTfjvhPGglOhuDhaDBJdzxdzvCwlcjmezyRWrAWzJjqvILRONMzxNBUJUfmCZvWffSYvfST[0]);
        var dugPcRqxCXqTMYeqqMIrLiBWOOqlcHBqrvNZDMOhZpqSDqqskwdePSdDhpSgiIPBfIkCOYCRhDOd = System.Int32.Parse(PubjPuTfjvhPGglOhuDhaDBJdzxdzvCwlcjmezyRWrAWzJjqvILRONMzxNBUJUfmCZvWffSYvfST[1]);
        var cPYjhCFzKzYftIcFQjkYDqhDfOMCNKpBwazgwgYKouarVClNrHzryWVORnsnlJChmDrMcjjpmYLb = new System.Collections.Generic.Queue<RBlQYfklICOtftnKZOrhMMHqcIHnhNUevjRFhpFekoxMzDpaBHqSgdDZmRsexwyrykMLiqiDcRFu>();
        for (int i = 0; i < UPPWbwXQduMtmpObiAqkPCTohxmkohgHbfkXvjfOvKZfyNMczXhYaddwKagVBOBXUnzrdAIrlgrJ; i++)
        {
            var keXFQjkJXFIvuPfQFKeUSYADGQkFCwtPDkwHepmrxfcXEOlhnYnvhLNZJcikYuIftJPMbLMEYrhH = System.Console.ReadLine().Split(' ');
            cPYjhCFzKzYftIcFQjkYDqhDfOMCNKpBwazgwgYKouarVClNrHzryWVORnsnlJChmDrMcjjpmYLb.Enqueue(new RBlQYfklICOtftnKZOrhMMHqcIHnhNUevjRFhpFekoxMzDpaBHqSgdDZmRsexwyrykMLiqiDcRFu{ KGikKmlxEfvttXtArkRxKFqlhkuSgBcploDlsrtBdbnbVrPpUCXEytXXmLpDjnGRIXuHRHuxbWxK = keXFQjkJXFIvuPfQFKeUSYADGQkFCwtPDkwHepmrxfcXEOlhnYnvhLNZJcikYuIftJPMbLMEYrhH[0], dQGrrjOgrQUqnAdEcpZAVArZDECxpCHKSPDVFzFpYpzuZJBtrZGpbWfBhGZphBhrWPDujtsYCawX = System.Int32.Parse(keXFQjkJXFIvuPfQFKeUSYADGQkFCwtPDkwHepmrxfcXEOlhnYnvhLNZJcikYuIftJPMbLMEYrhH[1])});
        }
        var hHZuTCHjhVBlWUevJqUMnhFytLVTNTetSEbPSbVMcOEfSfkyeqFpVJALTQJDJJBhuqCYvBzAJFwL = 0;
        while (cPYjhCFzKzYftIcFQjkYDqhDfOMCNKpBwazgwgYKouarVClNrHzryWVORnsnlJChmDrMcjjpmYLb.Count != 0)
        {
            var cOGgdZePsAcITPDKblVfcTXJCsAghdfnixYGHoseKQAElhZzrqgWxYAsjQUYZXfJEEldKPpXyuoJ = cPYjhCFzKzYftIcFQjkYDqhDfOMCNKpBwazgwgYKouarVClNrHzryWVORnsnlJChmDrMcjjpmYLb.Dequeue();
            cOGgdZePsAcITPDKblVfcTXJCsAghdfnixYGHoseKQAElhZzrqgWxYAsjQUYZXfJEEldKPpXyuoJ.dQGrrjOgrQUqnAdEcpZAVArZDECxpCHKSPDVFzFpYpzuZJBtrZGpbWfBhGZphBhrWPDujtsYCawX -= dugPcRqxCXqTMYeqqMIrLiBWOOqlcHBqrvNZDMOhZpqSDqqskwdePSdDhpSgiIPBfIkCOYCRhDOd;
            if (cOGgdZePsAcITPDKblVfcTXJCsAghdfnixYGHoseKQAElhZzrqgWxYAsjQUYZXfJEEldKPpXyuoJ.dQGrrjOgrQUqnAdEcpZAVArZDECxpCHKSPDVFzFpYpzuZJBtrZGpbWfBhGZphBhrWPDujtsYCawX <= 0)
            {
                hHZuTCHjhVBlWUevJqUMnhFytLVTNTetSEbPSbVMcOEfSfkyeqFpVJALTQJDJJBhuqCYvBzAJFwL += dugPcRqxCXqTMYeqqMIrLiBWOOqlcHBqrvNZDMOhZpqSDqqskwdePSdDhpSgiIPBfIkCOYCRhDOd + cOGgdZePsAcITPDKblVfcTXJCsAghdfnixYGHoseKQAElhZzrqgWxYAsjQUYZXfJEEldKPpXyuoJ.dQGrrjOgrQUqnAdEcpZAVArZDECxpCHKSPDVFzFpYpzuZJBtrZGpbWfBhGZphBhrWPDujtsYCawX;
                System.Console.WriteLine("{0} {1}", cOGgdZePsAcITPDKblVfcTXJCsAghdfnixYGHoseKQAElhZzrqgWxYAsjQUYZXfJEEldKPpXyuoJ.KGikKmlxEfvttXtArkRxKFqlhkuSgBcploDlsrtBdbnbVrPpUCXEytXXmLpDjnGRIXuHRHuxbWxK, hHZuTCHjhVBlWUevJqUMnhFytLVTNTetSEbPSbVMcOEfSfkyeqFpVJALTQJDJJBhuqCYvBzAJFwL);
            }
            else
            {
                hHZuTCHjhVBlWUevJqUMnhFytLVTNTetSEbPSbVMcOEfSfkyeqFpVJALTQJDJJBhuqCYvBzAJFwL += dugPcRqxCXqTMYeqqMIrLiBWOOqlcHBqrvNZDMOhZpqSDqqskwdePSdDhpSgiIPBfIkCOYCRhDOd;
                cPYjhCFzKzYftIcFQjkYDqhDfOMCNKpBwazgwgYKouarVClNrHzryWVORnsnlJChmDrMcjjpmYLb.Enqueue(cOGgdZePsAcITPDKblVfcTXJCsAghdfnixYGHoseKQAElhZzrqgWxYAsjQUYZXfJEEldKPpXyuoJ);
            }
        }
    }
}
















































































































































































































































































































































































































































































































































































































































































































































































Measured memory_bytes: 17416