#include<bits/stdc++.h>
using namespace std;
const int M=1e6+5;
const int inf=1e8+5;
int dp[910][8100],p[910][8100];
void pre()
{
for(int i=0;i<=900;i++)
{
for(int j=0;j<=8100;j++)
{
dp[i][j]=inf;
p[i][j]=10;
}
}
dp[0][0]=1; //minimum number of digit having sum=0 and squared sum=0
for(int i=0;i<=900;i++)
{
for(int j=0;j<=8100;j++)
{
for(int k=1;k<=9;k++)
{
if(i+k>900 || j+k*k>8100) continue;
if(dp[i+k][j+k*k]>=1+dp[i][j])
{
dp[i+k][j+k*k]=1+dp[i][j];
p[i+k][j+k*k]=min(p[i+k][j+k*k],k);
}
}
}
}
}
int main()
{
pre();
int t;
cin>>t;
while(t--)
{
string ans="";
int n,m;
cin>>n>>m;
if(n>900 || m>8100 || dp[n][m]>100)
{
cout<<"No solution"<<endl;
continue;
}
while(n && m)
{
int x=p[n][m];
ans+=x+'0';
n-=x;
m-=x*x;
}
sort(ans.begin(),ans.end());
cout<<ans<<endl;
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE09MWU2KzU7CmNvbnN0IGludCBpbmY9MWU4KzU7CmludCBkcFs5MTBdWzgxMDBdLHBbOTEwXVs4MTAwXTsKdm9pZCBwcmUoKQp7Cglmb3IoaW50IGk9MDtpPD05MDA7aSsrKQoJewoJCWZvcihpbnQgaj0wO2o8PTgxMDA7aisrKQoJCXsKCQkJZHBbaV1bal09aW5mOwoJCQlwW2ldW2pdPTEwOwoJCX0KCX0KCWRwWzBdWzBdPTE7IC8vbWluaW11bSBudW1iZXIgb2YgZGlnaXQgaGF2aW5nIHN1bT0wIGFuZCBzcXVhcmVkIHN1bT0wCglmb3IoaW50IGk9MDtpPD05MDA7aSsrKQoJewoJCWZvcihpbnQgaj0wO2o8PTgxMDA7aisrKQoJCXsKCQkJZm9yKGludCBrPTE7azw9OTtrKyspCgkJCXsKCQkJCWlmKGkraz45MDAgfHwg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