MINMXSTR: Problem with python Implementation

Hey everyone, I tried solving Min-Max String from Dementia 2020 in python.
Here is my solution: CodeChef: Practical coding for everyone
I used trie data structure. I inserted the new string in the trie whenever the query was of type 1 and when the query was of type 2, from the root I took min child and went to the bottom ( took max in case of type 3). Now, this solution is giving TLE in python 3 (which happens many times but passes in pypy3) and Runtime error in type 3 and I’m seriously not able to detect where is the problem. Can anyone please help me with this.