#include <iostream>
#include <cmath>
using namespace std;
//英语 抄博友程序
int main()
{
/*
while(1)
{
string st;
cin>>st;
cout<<(st[0]-'A'+1)-pow((st[1]-'A'+1),2)+pow((st[2]-'A'+1),3)-pow((st[3]-'A'+1),4)+pow((st[4]-'A'+1),5)<<endl;
}*/
while(1)
{
int x;
string s;
cin>>x>>s;
if(x==0 && s=="END")
{
break;
}
int n=s.size();
string jg=" ";
for(int a=1;a<=n;a++)
{
for(int b=1;b<=n;b++)
{
for(int c=1;c<=n;c++)
{
for(int d=1;d<=n;d++)
{
for(int e=1;e<=n;e++)
{
int ta=s[a-1]-'A'+1;
int tb=s[b-1]-'A'+1;
int tc=s[c-1]-'A'+1;
int td=s[d-1]-'A'+1;
int te=s[e-1]-'A'+1;
if((ta-tb*tb+tc*tc*tc-td*td*td*td+te*te*te*te*te)==x &&
a!=b && a!=c && a!=d && a!=e && b!=c && b!=d && b!=e && c!=d && c!=e && d!=e)
{
string t=" ";
t[0]=s[a-1];
t[1]=s[b-1];
t[2]=s[c-1];
t[3]=s[d-1];
t[4]=s[e-1];
if(jg==" " || t>jg)
{
jg=t;
}
}
}
}
}
}
}
if(jg==" ")
{
cout<<"no solution"<<endl;
}else
{
cout<<jg<<endl;
}
}
return 0;
}