As I mentioned, don’t assume you’re getting correct answers to the first eight test cases. SPOJ judge runs all test cases anyway, and doesn’t stop on the first failure.
You’ll need to share your code if you want us to take look. Only you and the problem setter can see your submissions to the actual problem.