Did you try running this? When I tested it on ideone, it only gave the result for one test case.
If you get problems, try seeing what exceptions you’re getting, instead of ignoring any that might be happening.
The problem is where you declare the buffered reader.