#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef trie<
string,
null_type,
trie_string_access_traits<>,
pat_trie_tag,
trie_prefix_search_node_update>
pref_trie;
main()
{
ios::sync_with_stdio(0);
cin.tie(0);
pref_trie base;
base.insert("sun");
string x;
while(cin>>x)
{
if(x[0]=='?')
{
cout<<x.substr(1)<<endl;
auto range=base.prefix_range(x.substr(1));
int t=0;
for(auto it=range.first;t<20 && it!=range.second;it++,t++)
cout<<" "<<*it<<endl;
}
else
base.insert(x.substr(1));
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmllX3BvbGljeS5ocHA+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsKCnR5cGVkZWYgdHJpZTwKc3RyaW5nLApudWxsX3R5cGUsCnRyaWVfc3RyaW5nX2FjY2Vzc190cmFpdHM8PiwKcGF0X3RyaWVfdGFnLAp0cmllX3ByZWZpeF9zZWFyY2hfbm9kZV91cGRhdGU+CnByZWZfdHJpZTsKCm1haW4oKQp7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKTsKICAgIGNpbi50aWUoMCk7CgogICAgcHJlZl90cmllIGJhc2U7CiAgICBiYXNlLmluc2VydCgic3VuIik7CiAgICBzdHJpbmcgeDsKICAgIHdoaWxlKGNpbj4+eCkKICAgIHsKICAgICAgICBpZih4WzBdPT0nPycpCiAgICAgICAgewogICAgICAgICAgICBjb3V0PDx4LnN1YnN0cigxKTw8ZW5kbDsKICAgICAgICAgICAgYXV0byByYW5nZT1iYXNlLnByZWZpeF9yYW5nZSh4LnN1YnN0cigxKSk7CiAgICAgICAgICAgIGludCB0PTA7CiAgICAgICAgICAgIGZvcihhdXRvIGl0PXJhbmdlLmZpcnN0O3Q8MjAgJiYgaXQhPXJhbmdlLnNlY29uZDtpdCsrLHQrKykKICAgICAgICAgICAgICAgIGNvdXQ8PCIgICI8PCppdDw8ZW5kbDsKICAgICAgICB9CiAgICAgICAgZWxzZQogICAgICAgICAgICBiYXNlLmluc2VydCh4LnN1YnN0cigxKSk7CiAgICB9Cgp9Cg==