#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<map> #include<algorithm> using namespace std; #define END "XXXXXX" const int SIZE=10000+16; map<string, string> dic; void Fun_in() { string s; while(cin>>s&&s.compare(END)) { string t=s; sort(t.begin(),t.end()); dic[s]=t; } } void Fun_out() { string word; while(cin>>word&&word.compare(END)) { bool flag=false; string t=word; sort(t.begin(),t.end()); for(map<string, string>:: iterator it=dic.begin();it!=dic.end();it++) { if(!it->second.compare(t)) { flag=true; cout<<it->first<<endl; } } if(!flag) cout<<"NOT A VALID WORD"<<endl; cout<<"******"<<endl; } } int main() { Fun_in(); Fun_out(); return 0; }