/*
ID: fniksic001
LANG: C
TASK: namenum
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXNAMES 5000
#define MAXNAMELEN 12

typedef struct {
    char *name[MAXNAMES];
    int n;
} dictionary;

char temp[MAXNAMELEN+1];
char number[MAXNAMELEN+1];
/* Each dictionary contains names of the same length */
dictionary dict[MAXNAMELEN];
int length,flag;
FILE *dictfile,*in,*out;

char codes[] = "ABCDEFGHIJKLMNOPRSTUVWXY";

void dict_add(dictionary *d,char *name) {
    d->name[d->n]=(char *)malloc((strlen(name)+1)*sizeof(char));
    strcpy(d->name[d->n],name);
    d->n++;
}    

int member(dictionary *d,char *name) {
    int l,r,m,compare;

    l=0;
    r=d->n-1;

    while (l<=r) {
	m=(l+r)/2;
	compare=strcmp(d->name[m],name);
	if (compare<0) l=m+1;
	else if (compare>0) r=m-1;
	else return 1;
    }

    return 0;
}

void dict_clean(dictionary *d) {
    while (d->n) {
	d->n--;
	free(d->name[d->n]);
    }
}

void solve(int i) {
    int j,index;
    
    if (i==length) {
	if (member(&dict[length-1],temp)) {
	    fprintf(out,"%s\n",temp);
	    flag=1;
	}
	return;
    }

    index=(number[i]-'0'-2)*3;
    for (j=0;j<3;j++) {
	temp[i]=codes[index+j];
	solve(i+1);
    }
}

int main(void) {
    dictfile=fopen("dict.txt","r");
    while (fscanf(dictfile,"%s",temp)!=EOF)
	dict_add(&dict[strlen(temp)-1],temp);
    fclose(dictfile);

    in=fopen("namenum.in","r");
    out=fopen("namenum.out","w");

    fscanf(in,"%s",number);
    length=strlen(number);
    temp[length]='\0';

    solve(0);
    if (!flag) fprintf(out,"NONE\n");

    fclose(in);
    fclose(out);

    for (length=0;length<MAXNAMELEN;dict_clean(&dict[length++]));

    return 0;
}
