#include <bits/stdc++.h>
using namespace std;
int main(){
long long n,k,t,s=1,temp,zonghe=0,total=0;
cin>>t;
for(int i=1;i<=t;i++){
cin>>n>>k;
for(int j=1;j<=n;j++){
s*=10;
}
for(int w=1;w<=s;w++){
temp=w;
while(temp>0){
zonghe+=temp%10;
temp/=10;
}
if(zonghe<=k){
total++;
}
zonghe=0;
}
s=1;
cout<<total-1<<endl;
total=0;
}
return 0;
}