Why does my solution fails? DEMENTIA Min-max string problem

Can anybody provide a test case for which my solution fails?
My solution: CodeChef: Practical coding for everyone

Even if your solution is correct, you are sorting the whole array of strings every time you get a query of type 2 or 3, bound to get TLE