import java.io.*;
import java.util.*;
public class SumDif {
public static void main(String[] args) throws IOException {
Vvod qt1 = new Vvod();
ArrayList<String> sVvod = qt1.BufR();
System.out.println(sVvod);
PerStr qt2 = new PerStr();
ArrayList<String> sPer = qt2.PerArL(sVvod);
System.out.println(sPer);
ResStr qt4 = new ResStr();
qt4.ResArL(sPer,sVvod);
}
}
class SopNum {
public char[] chs = new char[] {
'o', 'q', 'z',
'i', 'j',
'a', 'b', 'c',
'd', 'e', 'f',
'g', 'h',
'k', 'l',
'm', 'n',
'p', 'r', 's',
't', 'u', 'v',
'w', 'x', 'y'};
public int[] chsn = new int[] {
0, 0, 0,
1, 1,
2, 2, 2,
3, 3, 3,
4, 4,
5, 5,
6, 6,
7, 7, 7,
8, 8, 8,
9, 9, 9};
public int Number(char a1) {
int i = 0, k = -1;
for(; i < chs.length; i++)
if(a1 == chs[i])
k = chsn[i];
if(k == -1) {
String s = Character.toString(a1);
return Integer.parseInt(s);
}
else
return k;
}
}
class Vvod {
public ArrayList<String> BufR() {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> al = new ArrayList<String>();
try {
String st;
while((st = br.readLine()) != null) {
if(st.equals("-1")) break;
al.add(new String(st));
}
} catch (IOException e) {
e.printStackTrace();
}
return al;
}
}
class PerStr {
public ArrayList<String> PerArL(ArrayList<String> arL) {
ArrayList<String> alr = new ArrayList<String>();
for(int i = 0; i < arL.size(); i++) {
char chArs[] = new char[arL.size()];
chArs = arL.get(i).toCharArray();
int stInt[] = new int[chArs.length];
for(int j = 0; j < chArs.length; j++) {
SopNum qt2 = new SopNum();
int numCh = qt2.Number(chArs[j]);
stInt[j] = numCh;
}
StringBuffer s = new StringBuffer();
for(int j = 0; j < stInt.length; j++)
s.append(Integer.toString(stInt[j]));
alr.add(new String(s));
}
return alr;
}
}
class ResStr {
/*
public class MyComparator implements Comparator<String>{
@Override
public int compare(String o1, String o2) {
if (o1.length() > o2.length()) {
return -1;
} else if (o1.length() < o2.length()) {
return 1;
} else {
return o1.compareTo(o2);
}
}
}*/
public void ResArL(ArrayList<String> arL, ArrayList<String> arL2) {
Calculation res1 = new Calculation();
ArrayList<String> h = new ArrayList<String>();
ArrayList<String> h5 = new ArrayList<String>();
int countS = arL.size();
String beginStr;
int i = 0, c, v, num;
while(i < countS) {
beginStr = arL.get(i);
i++;
num = Integer.parseInt(arL.get(i));
i++;
num += i;
c = i; v = num;
for(; i < num; i++)
h.add(arL.get(i));
//Collections.sort(h, new MyComparator());
h5.removeAll(h5);
h5 = res1.Calc(0, beginStr, h, h5);
if(h5.size() > 0) {
StringBuffer strRes = new StringBuffer();
for(int o = c; o < v; o++) {
for(int q = 0; q < h5.size(); q++) {
if(arL.get(o).equals(h5.get(q)))
if(strRes.length() > 0) {
strRes.append(" ");
strRes.append(arL2.get(o));
} else {
strRes.append(arL2.get(o));
}
}
} System.out.println(strRes);
}
else
System.out.println("No Solution.");
h.removeAll(h);
}
}
}
class Calculation {
ArrayList<String> stAr = new ArrayList<String>();
ArrayList<String> stAr2 = new ArrayList<String>();
public ArrayList<String> Calc(int position, String number, ArrayList<String> dictionary, ArrayList<String> stAr2) {
for(int i = 0; i < dictionary.size(); i++) {
if(position == 0) stAr.removeAll(stAr);
if(number.indexOf(dictionary.get(i)) == position) {
int k = dictionary.get(i).length();
stAr.add(dictionary.get(i));
if((position+k) == number.length())
if(stAr2.size() < stAr.size()) {
stAr2.addAll(stAr);
}
Calc(k, number, dictionary, stAr2);
break;
}
}
return stAr2;
}
}