https://www.acwing.com/problem/content/1347/
#include<bits/stdc++.h>
using namespace std;
string s,ss,a;
vector<string>ve;
string hush[10]={"","","ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"};
int main(void)
{
cin>>s;
while(cin>>a)
{
bool flag=1;
if(a.size()!=s.size()) continue;
for(int i=0;i<a.size();i++)
if(hush[s[i]-'0'].find(a[i])==-1) {flag=0;break;}
if(flag) ve.push_back(a);
}
sort(ve.begin(),ve.end());
for(int i=0;i<ve.size();i++) cout<<ve[i]<<endl;
if(!ve.size()) puts("NONE");
return 0;
}