/*
看懂题意之后,给定target和大写字符串,即是:
把ABCDE……转换为12345……
在给定的不重复数之中找5个数,使得其
满足a-b^2+c^3-d^4+e^5等于给定的数target
由于数据量不大,最大为20个不重复大写字母,
不多说,5重for循环搞定
*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
#define input freopen("input.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define For1(i,a,b) for (i=a;i<b;i++)
#define For2(i,a,b) for (i=a;i<=b;i++)
#define Dec(i,a,b) for (i=a;i>b;i--)
#define Dec2(i,a,b) for (i=a;i>=b;i--)
#define Sca_d(x) scanf("%d",&x)
#define Sca_s(x) scanf("%s",x)
#define Sca_c(x) scanf("%c",&x)
#define Sca_f(x) scanf("%f",&x)
#define Sca_lf(x) scanf("%lf",&x)
#define Fill(x,a) memset(x,a,sizeof(x))
#define MAXN 0x7fffffff
int a,b,c,d,e;
int book[30];
int ans[10];
int main()
{
int x,i,j,k,l;
char ch[20];
while(cin>>x>>ch)
{
if (!x) break;
Fill(book,0);
Fill(ans,0);
l=strlen(ch);
For1(i,0,l) book[ch[i]-64]++;//数字字符统计
For2(a,1,26)
if (book[a])
For2(b,1,26)
if (a!=b&&book[b])
For2(c,1,26)
if (c!=a&&c!=b&&book[c])
For2(d,1,26)
if (d!=a&&d!=b&&d!=c&&book[d])
For2(e,1,26)
if (e!=a&&e!=b&&e!=c&&e!=d&&book[e])
if (a-b*b+c*c*c-d*d*d*d+e*e*e*e*e==x)
ans[1]=a,ans[2]=b,ans[3]=c,ans[4]=d,ans[5]=e;//直接暴力到最后一组
if (ans[1]==0)//如果直到搜索完毕还没有解的话,no
cout<<"no solution";
else
For2(i,1,5)
printf("%c",ans[i]+64);//记得将其转换为字符输出
cout<<endl;
}
return 0;
}