It is about read-process-output. Unlike most other SPOJ problems, in this problem your program does not 'know' in advance (by reading a first line) how many test cases it has got to process, so it is strongly recommended to process / loop over the input line by line and to check every single line whether it meets the stop condition.