[Solved] [SHKSTR] - Help needed

Problem link: Contest Page | CodeChef
Submission link: Solution: 57993713 | CodeChef

I have been trying to solve this problem for the past 2 hours. My approach uses Trie + Offline queries. I am unable to find out what is causing \text{RTE}. Can someone help me figure it out? :pleading_face: