Digital Dictionary from trie

Here’s my implementation for digital dictionary. I have written the half of the code but I don’t understand how to complete my search function.

Like as give in sample test case during q queries.
First query is “pe”, I should show pet and peter in lexicographical order. I am adding chars to my string so that at the end I can push them to my resultant vector. I am able to traverse till “pe” with the help of trie but once the word is finished how can I traverse??
PS:- I have commented out the part where the code is to be written. Please help.

use s.push_back() and s.pop_back() funtions
u can also see this