Welcome to ZOJ
Information
Select Problem
Runs
Ranklist
ZOJ Problem Set - 1481
Namenum

Time Limit: 5 Seconds      Memory Limit: 32768 KB

Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the members of their herd by a pleasing name rather than saying, "C'mon, #4734, get along."

Help the poor cowhands out by writing a program that will translate the brand serial number of a cow into possible names uniquely associated with that serial number. Since the cow hands all have cellular saddle phones these days, use the standard Touch-Tone(R) telephone keypad mapping to get from numbers to letters:

2: A,B,C,a,b,c
3: D,E,F,d,e,f
4: G,H,I,g,h,i
5: J,K,L,j,k,l
6: M,N,O,m,n,o
7: P,R,S,p,r,s
8: T,U,V,t,u,v
9: W,X,Y,w,x,y
0: Q,Z,q,z

Acceptable names for cattle are provided to you in the input, which contains a list of fewer than 50,000 acceptable cattle names. Take a cow's brand number and report which of all the possible words to which that number maps are in the given dictionary.

For instance, the brand number 4734 produces all the following names:

GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI
GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI
GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI
HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI
HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI
IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI
ISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI

As it happens, the only one of these 81 names that is in the list of valid names is "GREG".

Write a program that is given the brand number of a cow and prints all the valid names that can be generated from that brand number or "NONE" if there are no valid names. Serial numbers can be as many as 30 digits long.


Input

The first part of input is the dictionary of all valid names, one word per line. The dictionary ends with a line contains '#' only.

Following are several test cases, each test case has one single line with a number from 1 through 30 digits in length.


Output

For each test case, output one line of valid names that can be generated from the input(in alphabetic order), seperated by space.


Sample Input

GREG
AAAA
aaaa
BBBB
#
4734
2222
5555


Sample Output

GREG
AAAA BBBB aaaa
NONE



Author: CHENG, Long
Source: ZOJ Monthly, January 2003
Submit    Status