Are you going to solve this problem in c++ or java? Pick one. I'm not going to debug the same issues in each language.
You're getting sigsegv because you're exceeding your array bounds. You have assumed that there can be at most 100 tet cases, which is WRONG.
Input a testcase, output a result, move to the next test case.