HDU 3709
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll;
const int N=20;
ll l,r,f[N][N][2000];int T,bits[N];
ll dfs(int pos,int x,int st,bool lim){
if(!pos) return !st;
if(st<0) return 0;
ll ans=0;
if(!lim&&f[pos][x][st]!=-1) return f[pos][x][st];
int up=!lim?9:bits[pos];
for(int i=0;i<=up;i++){
ans+=dfs(pos-1,x,st+i*(pos-x),lim&&i==bits[pos]);
}
if(!lim) f[pos][x][st]=ans;
return ans;
}
ll solve(ll x){
if(x<0) return 0;
int len=0;ll ans=0;
for(;x;x/=10) bits[++len]=x%10;
for(int i=1;i<=len;i++) ans+=dfs(len,i,0,1);
return ans-len+1;0000000重复
}
int main(){
memset(f,-1,sizeof f);
scanf("%d",&T);
while(T--){
scanf("%I64d%I64d",&l,&r),
printf("%I64d\n",solve(r)-solve(l-1));
}
return 0;
}