WA in Temple Queues

,

problem: http://www.spoj.com/problems/TEMPLEQ/
solution: http://ideone.com/7CkURQ

My ans is coming is coming wrong for the 3rd and 4th answer as mention in ideone
plz help me rectify this code

Problem is also available in codechef peer section

after removing the lazy propogation it is giving the correct answer but tLE