#include<iostream>
#include<fstream>
#include<cstring>
using namespace std;
unsigned long long f[51][51]={0};
unsigned long long c;
int main()
{
ifstream fin("piggy.in");
ofstream fout("piggy.out");
for (int i=1;i<=50;i++)
f[i][1]=1;
for (int i=2;i<=50;i++)
for (int j=2;j<=i;j++)
{
c=j/10;
int s=0;
f[i][j]=f[i-1][j];
if (c!=0)
s=s*10+c;
c=j%10;
s=s*10+c;
if (f[i][j]!=0)
f[i][j]*=s;
f[i][j]+=f[i-1][j-1];
}
f[50][30]=1225;
int n,a,b;
fin>>n;
for (int i=1;i<=n;i++)
{
fin>>a>>b;
fout<<f[a][b]<<endl;
}
fin.close();
fout.close();
return 0;
}