My C++ code is AC in 1.7 sec. I first sort the dictionary in this order:
The words with shorter length come first, if they have equal length then
The lexicographically smaller words come first, otherwise
The words with smaller label come first.
Then for each query iterate through the dictionary until you have up to the top 10. I use std::string::find to see if the word contains the substring.
Check input and AC output for thousands of problems on uDebug!
But I think that this approach is not optimal. We make a lot of substring operations.
Suffix tree would be better, but my first implementation has O(n^2) to init the tree, I believe because of that I've got TLE