#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
using namespace std;
typedef long long ll;
ll n,m,k;
int q;
ll C[MAXN][MAXN];
void prepare(){
	C[0][0]=1;
	for(int i=1;i<=20;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int pos[MAXN];
ll num[MAXN];
ll solve(ll x){
	if(x==0)
		return 1;
	ll x1=x;
	int cnt=0,now=0;
	while(x){
		if(x%10ll){
			cnt++;
			pos[cnt]=now;
			num[cnt]=x%10ll;
		}
		x/=10ll;
		now++;
	}
	ll res=0;
	res+=num[cnt];
	if(cnt>1){
		res+=C[pos[cnt-1]][2]*9ll*9ll*num[cnt];
		res+=C[pos[cnt-1]][1]*9ll*num[cnt];
		res+=9ll*(num[cnt]-1ll);
		res+=num[cnt-1];
	}
	if(cnt>2){
		res+=C[pos[cnt-2]][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]);
		res+=9ll*9ll*(num[cnt]-1ll);
		res+=9ll*(num[cnt-1]-1ll);
		res+=num[cnt-2];
	}
	res+=C[now-1][3]*9ll*9ll*9ll;
	res+=C[now-1][2]*9ll*9ll;
	res+=C[now-1][1]*9ll;
	res++;
	return res;
}
int main(){
	prepare();
	SF("%d",&q);
	ll l,r;
	while(q--){
		SF("%I64d%I64d",&l,&r);
		PF("%I64d\n",solve(r)-solve(l-1));
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
using namespace std;
typedef long long ll;
ll n,m,k;
int q;
ll C[MAXN][MAXN];
void prepare(){
	C[0][0]=1;
	for(int i=1;i<=20;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int pos[MAXN];
ll num[MAXN];
ll solve(ll x){
	if(x==0)
		return 1;
	ll x1=x;
	int cnt=0,now=0;
	while(x){
		if(x%10ll){
			cnt++;
			pos[cnt]=now;
			num[cnt]=x%10ll;
		}
		x/=10ll;
		now++;
	}
	pos[0]=-1;
	ll res=0;
	res+=C[pos[cnt]-pos[cnt-1]-1][2]*9ll*9ll*(num[cnt]-1ll);
	res+=C[pos[cnt]-pos[cnt-1]-1][1]*9ll*(num[cnt]-1ll);
	res+=num[cnt];
	if(cnt>1){
		res+=C[pos[cnt-1]][2]*9ll*9ll*num[cnt];
		res+=C[pos[cnt-1]][1]*9ll*num[cnt];
		res+=9ll*(num[cnt]-1ll);
		res+=num[cnt-1];
	}
	if(cnt>2){
		res+=C[pos[cnt-2]][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]);
		res+=9ll*9ll*(num[cnt]-1ll);
		res+=9ll*(num[cnt-1]-1ll);
		res+=num[cnt-2];
	}
	res+=C[now-1][3]*9ll*9ll*9ll;
	res+=C[now-1][2]*9ll*9ll;
	res+=C[now-1][1]*9ll;
	res++;
	return res;
}
int main(){
	prepare();
	SF("%d",&q);
	ll l,r;
	while(q--){
		SF("%I64d%I64d",&l,&r);
		PF("%I64d\n",solve(r)-solve(l-1));
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
using namespace std;
typedef long long ll;
ll n,m,k;
int q;
ll C[MAXN][MAXN];
void prepare(){
	C[0][0]=1;
	for(int i=1;i<=20;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int pos[MAXN];
ll num[MAXN];
ll solve(ll x){
	if(x==0)
		return 1;
	ll x1=x;
	int cnt=0,now=0;
	while(x){
		if(x%10ll){
			cnt++;
			pos[cnt]=now;
			num[cnt]=x%10ll;
		}
		x/=10ll;
		now++;
	}
	pos[0]=-1;
	ll res=0;
	res+=C[pos[cnt]-pos[cnt-1]-1][2]*9ll*9ll*(num[cnt]-1ll);
	res+=(C[max(pos[cnt-1],0)][1]*9ll+1ll)*C[pos[cnt]-pos[cnt-1]-1][1]*9ll*(num[cnt]-1ll);
	res+=num[cnt];
	if(cnt>1){
		res+=C[pos[cnt-1]][2]*9ll*9ll*num[cnt];
		res+=C[pos[cnt-1]][1]*9ll*num[cnt];
		res+=C[pos[cnt-1]-pos[cnt-2]-1][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]-1ll);
		res+=9ll*(num[cnt]-1ll);
		res+=num[cnt-1];
	}
	if(cnt>2){
		res+=C[pos[cnt-2]][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]);
		res+=9ll*9ll*(num[cnt]-1ll);
		res+=9ll*(num[cnt-1]-1ll);
		res+=num[cnt-2];
	}
	res+=C[now-1][3]*9ll*9ll*9ll;
	res+=C[now-1][2]*9ll*9ll;
	res+=C[now-1][1]*9ll;
	res++;
	return res;
}
int main(){
	prepare();
	SF("%d",&q);
	ll l,r;
	while(q--){
		SF("%I64d%I64d",&l,&r);
		PF("%I64d\n",solve(r)-solve(l-1));
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
using namespace std;
typedef long long ll;
ll n,m,k;
int q;
ll C[MAXN][MAXN];
void prepare(){
	C[0][0]=1;
	for(int i=1;i<=20;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int pos[MAXN];
ll num[MAXN];
ll solve(ll x){
	if(x==0)
		return 1;
	ll x1=x;
	int cnt=0,now=0;
	while(x){
		if(x%10ll){
			cnt++;
			pos[cnt]=now;
			num[cnt]=x%10ll;
		}
		x/=10ll;
		now++;
	}
	pos[0]=-1;
	ll res=0;
	res+=C[pos[cnt]-pos[cnt-1]-1][2]*9ll*9ll*(num[cnt]-1ll);
	res+=C[pos[cnt]-pos[cnt-1]-1][1]*9ll*(num[cnt]-1ll);
	res+=num[cnt];
	if(cnt>1){
		res+=C[pos[cnt-1]][2]*9ll*9ll*num[cnt];
		res+=C[pos[cnt-1]][1]*9ll*num[cnt];
		res+=C[pos[cnt-1]-pos[cnt-2]-1][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]-1ll);
		res+=9ll*(num[cnt]-1ll);
		res+=num[cnt-1];
	}
	if(cnt>2){
		res+=C[pos[cnt-2]][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]);
		res+=9ll*9ll*(num[cnt]-1ll);
		res+=9ll*(num[cnt-1]-1ll);
		res+=num[cnt-2];
	}
	res+=C[now-1][3]*9ll*9ll*9ll;
	res+=C[now-1][2]*9ll*9ll;
	res+=C[now-1][1]*9ll;
	res++;
	return res;
}
int main(){
	prepare();
	SF("%d",&q);
	ll l,r;
	while(q--){
		SF("%I64d%I64d",&l,&r);
		PF("%I64d\n",solve(r)-solve(l-1));
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
using namespace std;
typedef long long ll;
ll n,m,k;
int q;
ll C[MAXN][MAXN];
void prepare(){
	C[0][0]=1;
	for(int i=1;i<=20;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int pos[MAXN];
ll num[MAXN];
ll solve(ll x){
	if(x==0)
		return 1;
	ll x1=x;
	int cnt=0,now=0;
	while(x){
		if(x%10ll){
			cnt++;
			pos[cnt]=now;
			num[cnt]=x%10ll;
		}
		x/=10ll;
		now++;
	}
	pos[0]=-1;
	ll res=0;
	res+=C[pos[cnt]-pos[cnt-1]-1][2]*9ll*9ll*(num[cnt]-1ll);
	res+=((C[max(pos[cnt-1],0)][1]+1ll)*9ll+1ll)*C[pos[cnt]-pos[cnt-1]-1][1]*9ll*(num[cnt]-1ll);
	res+=num[cnt];
	if(cnt>1){
		res+=C[pos[cnt-1]][2]*9ll*9ll*num[cnt];
		res+=C[pos[cnt-1]][1]*9ll*num[cnt];
		res+=C[pos[cnt-1]-pos[cnt-2]-1][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]-1ll);
		res+=9ll*(num[cnt]-1ll);
		res+=num[cnt-1];
	}
	if(cnt>2){
		res+=C[pos[cnt-2]][1]*9ll*(9ll*(num[cnt]-1ll)+num[cnt-1]);
		res+=9ll*9ll*(num[cnt]-1ll);
		res+=9ll*(num[cnt-1]-1ll);
		res+=num[cnt-2];
	}
	res+=C[now-1][3]*9ll*9ll*9ll;
	res+=C[now-1][2]*9ll*9ll;
	res+=C[now-1][1]*9ll;
	res++;
	return res;
}
int main(){
	prepare();
	SF("%d",&q);
	ll l,r;
	while(q--){
		SF("%I64d%I64d",&l,&r);
		PF("%I64d\n",solve(r)-solve(l-1));
	}
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 110
using namespace std;
typedef long long ll;
ll n,m,k;
int q;
ll C[MAXN][MAXN];
void prepare(){
	C[0][0]=1;
	for(int i=1;i<=20;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++)
			C[i][j]=C[i-1][j-1]+C[i-1][j];
	}
}
int pos[MAXN];
ll num[MAXN];
ll solve(ll x){
	if(x==0)
		return 1;
	ll x1=x;
	int cnt=0,now=0;
	while(x){
		if(x%10ll){
			cnt++;
			pos[cnt]=now;
			num[cnt]=x%10ll;
		}
		x/=10ll;
		now++;
	}
	ll res=0;
	res+=num[cnt];
	if(cnt>1){
		res+=C[pos[cnt-1]][2]*9ll*9ll*num[cnt];
		res+=C[pos[cnt-1]][1]*9ll*num[cnt];
		res+=num[cnt-1]*num[cnt];
	}
	if(cnt>2){
		res+=C[pos[cnt-2]][1]*9ll*num[cnt]*num[cnt-1];
		res+=num[cnt-2]*num[cnt]*num[cnt-1];
	}
	res+=C[now-1][3]*9ll*9ll*9ll;
	res+=C[now-1][2]*9ll*9ll;
	res+=C[now-1][1]*9ll;
	res++;
	return res;
}
int main(){
	prepare();
	SF("%d",&q);
	ll l,r;
	while(q--){
		SF("%I64d%I64d",&l,&r);
		PF("%I64d\n",solve(r)-solve(l-1));
	}
}


#include <bits/stdc++.h>
#define lll long long
#define pii pair<int,int>
#define pll pair<lll,lll>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define inf (INT_MAX/2-1)
#define infl (1LL<<61)
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<' '<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<=n;_++) cerr<<x[_]<<" ";cerr<<'\n'; aaa

using namespace std;

int cif[20], loc[20];

int ncf ( lll n )
{
  int x = 0;
  for (; n > 0; n /= 10, x++);
  return x;
}

bool cmp ()
{
  int i = 0;
  while (i < 19 && cif[i] == loc[i]) i++;
  return i == 19 || loc[i] < cif[i];
}

int f ( lll n )
{
  int i, j, z, nc = ncf(n);
  int ind[3], ans = 0;
  lll cn;
  memset (cif, 0, sizeof cif);
  for ( i = nc - 1, cn = n; i >= 0; i--, cn /= 10 ) cif[i] = cn % 10;
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for (z = j+1; z < nc; z++)
        for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
          for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
            for ( ind[2] = 1; ind[2] <= 9; ind[2]++ )
            {
              memset (loc, 0, sizeof loc);
              loc[i] = ind[0]; loc[j] = ind[1]; loc[z] = ind[2];
              if (cmp()) ans++;
            }
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
        for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
        {
          memset (loc, 0, sizeof loc);
          loc[i] = ind[0]; loc[j] = ind[1];
          if (cmp()) ans++;
        }
  for (i = 0; i < nc; i++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
      {
        memset (loc, 0, sizeof loc);
        loc[i] = ind[0];
        if (cmp()) ans++;
      }
  return ans;
}

int main ()
{
  ios::sync_with_stdio (false); cin.tie(0); cout.tie(0);
  int t; cin >> t;
  lll l, r;
  while (t--)
  {
    cin >> l >> r;
    cout << f(r) - f(l-1) << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>
#define lll long long
#define pii pair<int,int>
#define pll pair<lll,lll>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define inf (INT_MAX/2-1)
#define infl (1LL<<61)
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<' '<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<=n;_++) cerr<<x[_]<<" ";cerr<<'\n'; aaa

using namespace std;

int cif[20], loc[20];
map <lll,bool> has;
map <lll,int> sol;

int ncf ( lll n )
{
  int x = 0;
  for (; n > 0; n /= 10, x++);
  return x;
}

bool cmp ()
{
  int i = 0;
  while (i < 19 && cif[i] == loc[i]) i++;
  return i == 19 || loc[i] < cif[i];
}

int f ( lll n )
{
  if (has[n] == 1) return sol[n];
  int i, j, z, nc = ncf(n);
  int ind[3], ans = 0;
  lll cn;
  memset (cif, 0, sizeof cif);
  memset (loc, 0, sizeof loc);
  for ( i = nc - 1, cn = n; i >= 0; i--, cn /= 10 ) cif[i] = cn % 10;
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for (z = j+1; z < nc; z++)
        for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
          for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
            for ( ind[2] = 1; ind[2] <= 9; ind[2]++ )
            {
              loc[i] = ind[0]; loc[j] = ind[1]; loc[z] = ind[2];
              if (cmp()) ans++;
              loc[i] = 0; loc[j] = 0; loc[z] = 0;
            }
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
        for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
        {
          loc[i] = ind[0]; loc[j] = ind[1];
          if (cmp()) ans++;
          loc[i] = 0; loc[j] = 0;
        }
  for (i = 0; i < nc; i++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
      {
        loc[i] = ind[0];
        if (cmp()) ans++;
        loc[i] = 0;
      }
  has[n] = 1;
  sol[n] = ans;
  return ans;
}

int main ()
{
  ios::sync_with_stdio (false); cin.tie(0); cout.tie(0);
  int t; cin >> t;
  lll l, r;
  while (t--)
  {
    cin >> l >> r;
    cout << f(r) - f(l-1) << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>
#define lll long long
#define pii pair<int,int>
#define pll pair<lll,lll>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define inf (INT_MAX/2-1)
#define infl (1LL<<61)
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<' '<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<=n;_++) cerr<<x[_]<<" ";cerr<<'\n'; aaa

using namespace std;

int cif[20], loc[20];

int ncf ( lll n )
{
  int x = 0;
  for (; n > 0; n /= 10, x++);
  return x;
}

bool cmp ()
{
  int i = 0;
  while (i < 19 && cif[i] == loc[i]) i++;
  return i == 19 || loc[i] < cif[i];
}

int f ( lll n )
{
  int i, j, z, nc = ncf(n);
  int ind[3], ans = 0;
  lll cn;
  memset (cif, 0, sizeof cif);
  memset (loc, 0, sizeof loc);
  for ( i = nc - 1, cn = n; i >= 0; i--, cn /= 10 ) cif[i] = cn % 10;
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for (z = j+1; z < nc; z++)
        for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
          for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
            for ( ind[2] = 1; ind[2] <= 9; ind[2]++ )
            {
              loc[i] = ind[0]; loc[j] = ind[1]; loc[z] = ind[2];
              if (cmp()) ans++;
              loc[i] = 0; loc[j] = 0; loc[z] = 0;
            }
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
        for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
        {
          loc[i] = ind[0]; loc[j] = ind[1];
          if (cmp()) ans++;
          loc[i] = 0; loc[j] = 0;
        }
  for (i = 0; i < nc; i++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
      {
        loc[i] = ind[0];
        if (cmp()) ans++;
        loc[i] = 0;
      }
  return ans;
}

int main ()
{
  ios::sync_with_stdio (false); cin.tie(0); cout.tie(0);
  int t; cin >> t;
  lll l, r;
  while (t--)
  {
    cin >> l >> r;
    cout << f(r) - f(l-1) << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>
#define lll long long
#define pii pair<int,int>
#define pll pair<lll,lll>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define inf (INT_MAX/2-1)
#define infl (1LL<<61)
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<' '<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<=n;_++) cerr<<x[_]<<" ";cerr<<'\n'; aaa

using namespace std;

lll p10[20];
vector<lll> gen;

void generator ()
{
  int i, j, z, nc = 17;
  int ind[3], ans = 0;
  lll cn;
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for (z = j+1; z < nc; z++)
        for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
          for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
            for ( ind[2] = 1; ind[2] <= 9; ind[2]++ ) gen.pb(ind[0]*p10[i]+ind[1]*p10[j]+ind[2]*p10[z]);
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
        for ( ind[1] = 1; ind[1] <= 9; ind[1]++ ) gen.pb(ind[0]*p10[i]+ind[1]*p10[j]);
  for (i = 0; i < nc; i++)
    for ( ind[0] = 1; ind[0] <= 9; ind[0]++ ) gen.pb(ind[0]*p10[i]);
  gen.pb(p10[18]);
  sort (gen.begin(), gen.end());
}

int f ( lll z )
{
  auto it = upper_bound (gen.begin(), gen.end(), z) - gen.begin();
  return it + 1;
}

int main ()
{
  ios::sync_with_stdio (false); cin.tie(0); cout.tie(0);
  int i, j, z;
  lll p = 1;
  for (i = 0; i <= 18; i++) p10[i] = p, p *= 10;
  generator();
  int t; cin >> t;
  lll l, r;
  while (t--)
  {
    cin >> l >> r;
    cout << f(r) - f(l-1) << '\n';
  }
  return 0;
}


#include <bits/stdc++.h>
#define lll long long
#define pii pair<int,int>
#define pll pair<lll,lll>
#define fi first
#define se second
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define inf (INT_MAX/2-1)
#define infl (1LL<<61)
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<' '<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<=n;_++) cerr<<x[_]<<" ";cerr<<'\n'; aaa

using namespace std;

lll p10[20];
vector<lll> gen;

void generator ()
{
  int i, j, z, nc = 18;
  int ind[3], ans = 0;
  lll cn;
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for (z = j+1; z < nc; z++)
        for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
          for ( ind[1] = 1; ind[1] <= 9; ind[1]++ )
            for ( ind[2] = 1; ind[2] <= 9; ind[2]++ )
              gen.pb(ind[0]*p10[nc-1-i]+ind[1]*p10[nc-1-j]+ind[2]*p10[nc-1-z]);
  for (i = 0; i < nc; i++)
    for (j = i+1; j < nc; j++)
      for ( ind[0] = 1; ind[0] <= 9; ind[0]++ )
        for ( ind[1] = 1; ind[1] <= 9; ind[1]++ ) gen.pb(ind[0]*p10[nc-1-i]+ind[1]*p10[nc-1-j]);
  for (i = 0; i < nc; i++)
    for ( ind[0] = 1; ind[0] <= 9; ind[0]++ ) gen.pb(ind[0]*p10[nc-1-i]);
  gen.pb(p10[18]);
  gen.pb(0);
  sort (gen.begin(), gen.end());
}

int f ( lll z )
{
  auto it = upper_bound (gen.begin(), gen.end(), z) - gen.begin();
  return it + 1;
}

int main ()
{
  ios::sync_with_stdio (false); cin.tie(0); cout.tie(0);
  int i, j, z;
  lll p = 1;
  for (i = 0; i <= 18; i++) p10[i] = p, p *= 10;
  generator();
  int t; cin >> t;
  lll l, r;
  while (t--)
  {
    cin >> l >> r;
    cout << f(r) - f(l-1) << '\n';
  }
  return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long LL;
LL num[4][20];
LL sum(LL n){
    LL d=1e18,ans=0;
    int i=19,j=3;
    while(i&&j){
        if(n/d){
            ans+=(n/d-1)*num[j-1][i]+num[j][i];
            j--;
            n%=d;
        }
        i--;
        d/=10;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    num[1][2]=9;
    for(int i=3;i<=19;i++){
        num[1][i]=num[1][i-1]+9;
        num[2][i]=num[2][i-1]+9*num[1][i-1];
        num[3][i]=num[3][i-1]+9*num[2][i-1];
    }
    for(int i=1;i<=19;i++){
    	num[0][i]=1;
        num[1][i]++;
        num[2][i]+=num[1][i];
        num[3][i]+=num[2][i];
    }
    int T;LL a,b;
    cin>>T;
    while(T--){
        cin>>a>>b;
        cout<< sum(b)-sum(a-1) <<endl;
    }
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long LL;
LL num[4][20];
LL sum(LL n){
    LL d=1e18,ans=0;
    int i=19,j=3;
    while(i&&j){
        if(n/d){
            ans+=(n/d-1)*num[j-1][i]+num[j][i];
            j--;
            n%=d;
        }
        i--;
        d/=10;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false);
    num[1][2]=9;
    for(int i=3;i<=18;i++){
        num[1][i]=num[1][i-1]+9;
        num[2][i]=num[2][i-1]+9*num[1][i-1];
        num[3][i]=num[3][i-1]+9*num[2][i-1];
    }
    for(int i=1;i<=18;i++){
    	num[0][i]=1;
        num[1][i]++;
        num[2][i]+=num[1][i];
        num[3][i]+=num[2][i];
    }
    int T;LL a,b;
    cin>>T;
    while(T--){
        cin>>a>>b;
        cout<< sum(b)-sum(a-1) <<endl;
    }
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long LL;
vector<LL>v;
void add(LL n,int m){
    if(n>1e18||m>3)
        return;
    v.push_back(n);
    add(n*10,m);
    for(int i=1;i<10;i++)
        add(n*10+i,m+1);
}
int main(){
    for(int i=1;i<10;i++)
        add(i,1);
    sort(v.begin(),v.end());
    int T;LL l,r;
    scanf("%d",&T);
    while(T--){
        scanf("%lld%lld",&l,&r);
        printf("%d\n",upper_bound(v.begin(),v.end(),r)-lower_bound(v.begin(),v.end(),l));
    }
    return 0;
}


#include"bits/stdc++.h"
using namespace std;
const int inf=0x3f3f3f3f;
typedef long long LL;
vector<LL>v;
void add(LL n,int m){
    v.push_back(n);
    if(n>1e17)return;
    add(n*10,m);
    if(m>2)return;
    for(int i=1;i<10;i++)
        add(n*10+i,m+1);
}
int main(){
    v.clear();
    for(int i=1;i<10;i++)
        add(i,1);
    sort(v.begin(),v.end());
    int T;LL l,r;
    scanf("%d",&T);
    while(T--){
        scanf("%lld%lld",&l,&r);
        printf("%d\n",upper_bound(v.begin(),v.end(),r)-lower_bound(v.begin(),v.end(),l));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define rep0(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)

//const int MAX=1e18;
typedef long long int ll;
typedef vector<ll> vll;
vll res;

void brute(int pos,int cnt,ll cur)
{
	if(pos==18)
	{
		res.push_back(cur);
		return;
	}
	brute(pos+1,cnt,cur*10);
	if(cnt<3)
	{
		rep1(i,1,9)
		{
			brute(pos+1,cnt+1,cur*10+i);
		}
	}
}
int solve()
{
	brute(0,0,0);
	//res.push_back(1000000000000000000);
	int T;
	cin>>T;
	while(T--)
	{
		long long int L,R;
		cin>>L>>R;
		cout<<(int)(upper_bound(res.begin(),res.end(),R)-lower_bound(res.begin(),res.end(),L))<<endl;
	}
}
int main()
{

	solve();
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

#define rep0(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)

//const int MAX=1e18;
typedef long long int ll;
typedef vector<ll> vll;
vll res;

void brute(int pos,int cnt,ll cur)
{
	if(pos==18)
	{
		res.push_back(cur);
		return;
	}
	brute(pos+1,cnt,cur*10);
	if(cnt<3)
	{
		rep1(i,1,9)
		{
			brute(pos+1,cnt+1,cur*10+i);
		}
	}
}
int solve()
{
	brute(0,0,0);
	res.push_back(1000000000000000000);
	int T;
	cin>>T;
	while(T--)
	{
		long long int L,R;
		cin>>L>>R;
		cout<<(int)(upper_bound(res.begin(),res.end(),R)-lower_bound(res.begin(),res.end(),L));
	}
}
int main()
{

	solve();
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

#define rep0(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)

//const int MAX=1e18;
typedef long long int ll;
typedef vector<ll> vll;
vll res;

void brute(int pos,int cnt,ll cur)
{
	if(pos==18)
	{
		res.push_back(cur);
		return;
	}
	brute(pos+1,cnt,cur*10);
	if(cnt<3)
	{
		rep1(i,1,9)
		{
			brute(pos+1,cnt+1,cur*10+i);
		}
	}
}
int solve()
{
	brute(0,0,0);
	res.push_back(1000000000000000000);
	int T;
	cin>>T;
	while(T--)
	{
		long long int L,R;
		cin>>L>>R;
		cout<<(int)(upper_bound(res.begin(),res.end(),R)-lower_bound(res.begin(),res.end(),L))<<endl;
	}
}
int main()
{

	solve();
	return 0;

}


#include<bits/stdc++.h>
using namespace std;

#define rep0(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)

//const int MAX=1e18;
typedef long long int ll;
typedef vector<ll> vll;
vll res;

void brute(int pos,int cnt,ll cur)
{
	if(pos==18)
	{
		res.push_back(cur);
		return;
	}
	brute(pos+1,cnt,cur*10);
	if(cnt<3)
	{
		rep1(i,1,9)
		{
			brute(pos+1,cnt+1,cur*10+i);
		}
	}
}
int solve()
{
	brute(0,0,0);
	//res.push_back(1000000000000000000);
	int T;
	cin>>T;
	while(T--)
	{
		long long int L,R;
		cin>>L>>R;
		cout<<(int)(upper_bound(res.begin(),res.end(),R)-lower_bound(res.begin(),res.end(),L));
	}
}
int main()
{

	solve();
	return 0;

}


#include <cstring>
#include <cstdio>
using namespace std;
long long dp[20][4];
int num[20];
int dfs(int pos,int cnt,bool _0,bool _l)
{
	if(!_0&&!_l&&dp[pos][cnt]!=-1)return dp[pos][cnt];
	if(cnt>3)return 0;
	if(pos==0)return 1;
	int limit=(_l?num[pos]:9);
	long long ans(0);
	for(int i=0;i<=limit;++i)
		ans+=dfs(pos-1,cnt+(i!=0),_0&&!i,_l&&(i==num[pos]));
	if(!_0&&!_l)
		dp[pos][cnt]=ans;
	return ans;
}
long long solve(long long k)
{
	int len=0;
	while(k)
	{
		num[++len]=k%10;
		k/=10;
	}
	return dfs(len,0,1,1);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	long long l,r;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld%lld",&l,&r);
		printf("%lld\n",solve(r)-solve(l-1));
	}
	return 0;
}


constexpr auto Inf = 0X3F3F3F3F;
#ifndef LOCAL
	#include <bits/stdc++.h>
#endif
typedef long long LL;
using namespace std;

namespace IO {
	inline LL read() {
		LL o = 0, f = 1; char c = getchar();
		while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
		while (c > '/' && c < ':') { o = o * 10 + c - '0'; c = getchar(); }
		return o * f;
	}
	inline char recd() {
		char o; while ((o = getchar()) != 'a' && o != 'd' &&  o != 's'); return o;
	}
}
using namespace IO;

const int SIZE = 2E1 + 7, Mod = 1E9 + 7;

LL Dp[SIZE][SIZE][2], d[SIZE], Len;

LL DFS(int pos, int To, int lim) {
	if (!pos) return To <= 3;
	if (Dp[pos][To][lim] != -1) return Dp[pos][To][lim];
	LL res = 0, R = lim ? 9 : d[pos];
	for (int L = 0; L <= R; L++)
		res += DFS(pos - 1, To + (L != 0), lim || (L != d[pos]));
	return Dp[pos][To][lim] = res;
}

LL Sp(LL N) {
	Len = 0;
	while (N) d[++Len] = N % 10, N /= 10;
	memset(Dp, -1, sizeof Dp);
	return DFS(Len, 0, 0);
}

int main() {
	int T = read();
	while (T--) {
		LL L = read(), R = read();
		printf("%lld\n", Sp(R) - Sp(L - 1));
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAXN 20
using namespace std;
int n;
long long done[MAXN][MAXN],a[MAXN][MAXN];
long long l,r,ll,rr,aa[MAXN];
inline long long search1(long long pos,int sum,bool lead,bool limit)
{
	if(pos==0)
	{
		if(sum<=3) return 1;
		else return 0;
	}
	if(!lead&&!limit&&done[pos][sum]) return a[pos][sum];
	long long maxx=limit?aa[pos]:9;
	long long ans=0;
	for(int i=0;i<=maxx;i++)
		ans+=search1(pos-1,i==0?sum:sum+1,lead&&i==0,limit&&aa[pos]==i);
	if(!lead&&!limit) done[pos][sum]=1,a[pos][sum]=ans;
	return ans;
}
long long solve(long long x)
{
	memset(a,0,sizeof(a));
	memset(done,0,sizeof(done));
	int cnt=0;
	if(x==0) return 1;
	while(x)
	{
		aa[++cnt]=x%10;
		x/=10;
	}
	return search1(cnt,0,1,1);
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld%lld",&l,&r);
		//cout<<solve(r)<<" "<<solve(l-1)<<endl;
		printf("%lld\n",solve(r)-solve(l-1));
	}
	return 0;
 }


#include<bits/stdc++.h>
#define sz 201010
#define mod 998244353
using namespace std;
typedef long long ll;
struct FastIO
{
    inline FastIO& operator>>(int& x)
    {
        x=0;char f=0,ch=getchar();
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
        return x=(f?-x:x),*this;
    }
    inline FastIO& operator>>(ll& x)
    {
        x=0;char f=0,ch=getchar();
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
        return x=(f?-x:x),*this;
    }
    inline FastIO& operator>>(double& x)
    {
        x=0;char f=0,ch=getchar();
        double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') x=x*10+ch-48,ch=getchar();
        if(ch=='.')
        {
        	ch=getchar();
            while(ch<='9'&&ch>='0') x+=d*(ch^48),d*=0.1,ch=getchar();
        }
        return x=(f?-x:x),*this;
    }
}read;
void file()
{
    #ifndef ONLINE_JUDGE
    freopen("a.txt","r",stdin);
    #endif
}
unsigned int log2(int x){unsigned int ret;__asm__ __volatile__ ("bsrl %1, %%eax":"=a"(ret):"m"(x));return ret;}
inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ll dp[23][5];
int bit[23];
ll dfs(int cur,int num,bool lim)
{
	if (num>3) return 0;
	if (!cur) return 1;
	if (!lim&&dp[cur][num]!=-1) return dp[cur][num];
	int end=lim?bit[cur]:9;
	ll ret=0;
	for (int i=0;i<=end;i++)
	{
		ret+=dfs(cur-1,num+(bool)i,lim&&i==end);
	}
	if (!lim) dp[cur][num]=ret;
	return ret;
}
ll solve(ll x)
{
	if (!x) return 1;
	int cnt=0;memset(bit,0,sizeof(bit));
	while (x) bit[++cnt]=x%10,x/=10;
	return dfs(cnt,0,1);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	file();
	ll L,R,T;
	read>>T;
	while (T--)
	{
		read>>L>>R;
		printf("%lld\n",solve(R)-solve(L-1));
	}
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
#define maxn 20
using namespace std;
long long memo[maxn][5][3];
char l[maxn],r[maxn];
char s[maxn];
int t,len;
long long dfs(int cur,int m,int f)
{
	if(cur>len) return 1;
	if(memo[cur][m][f]!=-1) return memo[cur][m][f];
	int v;
	long long res=0;
	v=(f?s[cur]-'0':9);
	for(int i=0;i<=v;i++)
	{
		if(!i) res+=dfs(cur+1,m,f&(i==v));
		else
		{
			if(m==3) continue;
			else res+=dfs(cur+1,m+1,f&(i==v));
		}
	}
	return memo[cur][m][f]=res;
}
long long solve(char x[])
{
	len=strlen(x+1);
	for(int i=1;i<=len;i++) s[i]=x[i];
	memset(memo,-1,sizeof(memo));
	return dfs(1,0,1);
}
int check(char x[])
{
	len=strlen(x+1);
	int cnt=0;
	for(int i=1;i<=len;i++)
	{
		if(x[i]!='0') cnt++;
		if(cnt>3) return 0;
	}
	return 1;
}
int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%s",l+1);
		scanf("%s",r+1);
		printf("%lld\n",solve(r)-solve(l)+check(l));
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t;
ll a[20],f[20][20];
ll dfs(ll pos,ll now,ll b){
	if(pos==0) return 1;
	if(!b && f[pos][now]!=-1) return f[pos][now];
	ll maxx=b ? a[pos] : 9;
	ll ans=0;
	for(int i=0;i<=maxx;i++){
		if(i==0) ans+=dfs(pos-1,now,b && a[pos]==i);
		else if(now!=3) ans+=dfs(pos-1,now+1,b && a[pos]==i);
	}
	if(!b) f[pos][now]=ans;
	return ans;
}
inline ll sol(int x){
	ll tot=0;
	while(x>0){
		a[++tot]=x%10;x/=10;
	}
	memset(f,-1,sizeof(f));
	dfs(tot,0,1);
}
int main()
{
	scanf("%d",&t);
	while(t--){
		ll r,l;scanf("%lld%lld",&l,&r);
		printf("%lld\n",sol(r)-sol(l-1));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long dp[20][5][2];
int t;
long long dfs(int cur,int s,string r,int limit)
{
	if(dp[cur][s][limit]!=0) return dp[cur][s][limit];
	if(s>3) return 0;
	if(cur==r.length()+1) return 1;
	long long res;
	if(limit==1)
		res=dfs(cur+1,s,r,1)+9*dfs(cur+1,s+1,r,1);
	else
	{
		res=dfs(cur+1,s,r,(0<(r[cur-1]-'0')));
		if(r[cur-1]-'0'!=0) res+=dfs(cur+1,s+1,r,0);
		if(r[cur-1]-'0'>1) res+=(r[cur-1]-'0'-1)*dfs(cur+1,s+1,r,1);
	}

//	cout<<cur<<" "<<s<<" "<<limit<<": ";
//	cout<<res<<endl;
	dp[cur][s][limit]=res;
	return res;
}
int main()
{
	cin>>t;
	while(t--)
	{
		memset(dp,0,sizeof(dp));
		long long l1,r1;
		string l,r;
		scanf("%lld%lld",&l1,&r1);
		while(r1)
		{
			r.insert(0,1,'0'+r1%10);
			r1/=10;
		}
		if(l1==0) printf("%lld",dfs(1,0,r,0));
		else
		{
			l1--;
			if(l1==0) l.insert(0,1,'0');
			while(l1)
			{
				l.insert(0,1,'0'+l1%10);
				l1/=10;
			}
	//		cout<<l<<" "<<r<<endl;
			long long x=dfs(1,0,r,0);
			memset(dp,0,sizeof(dp));
			long long y=dfs(1,0,l,0);
			printf("%lld",x-y);
		}
		printf("\n");
	}
	return 0;
 }


#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define reg register
typedef long long ll;
const int kmaxn=25;
ll dp[kmaxn][10][4];
ll cnt[kmaxn][4];
ll m[kmaxn];
int n;
void output(int i)
{
	cout<<"num	"<<i<<endl;
	for(reg int i=1;i<=n;++i)
	{
		for(reg int p=0;p<=3;++p)
		{
			for(reg int j=0;j<10;++j)
				cout<<(ll)dp[i][j][p]<<' ';
			cout<<endl;
		}
		cout<<endl;
	}
}
void init()
{
	for(reg int i=0;i<=n;++i)
	{
		m[i]=0;
		for(reg int j=0;j<10;++j)
			dp[i][j][0]=dp[i][j][1]=dp[i][j][2]=dp[i][j][3]=0;
	}
//	output(1);
	m[0]=1;
	for(reg int i=0;i<=n;++i)
		m[i]=10*m[i-1];
	dp[1][0][0]=1;
	for(reg int i=1;i<10;++i)
		dp[1][i][1]=1;
	for(reg int i=2;i<=n;++i)
	{
		dp[i][0][0]=dp[i-1][0][0];
		for(reg int k=1;k<=3;++k)
		{
			for(reg int j=0;j<10;++j){
				dp[i][0][k]+=dp[i-1][j][k];
	//			cout<<"POS	"<<i-1<<"	"<<j<<"	"<<k<<"	"<<dp[i-1][j][k]<<"	"<<dp[i][0][k]<<endl;
			}
			for(reg int j=1;j<10;++j)
			{
				for(reg int p=0;p<10;++p)
				{
					dp[i][j][k]+=dp[i-1][p][k-1];
				}
			}
		}
	}
}
ll query(vector<int> vec)
{
	if(vec.size()==1&&vec[0]==0)return 0;
	ll ans=0;
	int cnt=0;
	for(reg int i=vec.size();i>0;--i)
	{
		for(reg int j=0;j<vec[i-1];++j)
		{
			if(cnt>3)
				return ans+1;
			for(reg int k=max(0,1-cnt);k<=3-cnt;++k)
			{
			//	cout<<"pos	"<<i<<"	"<<j<<"	"<<k<<"	"<<dp[i][j][k]<<endl;
				ans+=dp[i][j][k];
			}
		}
		if(vec[i-1])++cnt;
		//top
	}
	return ans+1;
}
inline vector<int> trans(const string& str)
{
    vector<int> vec;
    for(reg int i=str.size()-1;i>=0;--i)
    {
        vec.push_back(str[i]-'0');
    }
    return vec;
}
inline void add(vector<int>& vec)
{
    int t=1;
    for(reg int i=0,j=vec.size();i<j;++i)
    {
        vec[i]+=t;
        t=vec[i]/10;
        vec[i]%=10;
    }
    if(t)
        vec.push_back(t);
}
string l,r;
vector<int> lv,rv;
int solve()
{
	cin>>l>>r;
	lv=trans(l);
	rv=trans(r);
	add(rv);
	n=rv.size();
	init();
//	output(10);
	ll ans1,ans2;
	ans1=query(lv);
	ans2=query(rv);
//	cout<<ans2<<endl;
//	cout<<ans1<<endl;
	cout<<ans2-ans1<<endl;
	return 0;
}
int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define reg register
typedef long long ll;
const int kmaxn=25;
ll dp[kmaxn][10][4];
int n;
void init()
{
    dp[1][0][0]=1;
    for(reg int i=1;i<10;++i)
        dp[1][i][1]=1;
    for(reg int i=2;i<=n;++i)
    {
        dp[i][0][0]=dp[i-1][0][0];
        for(reg int k=1;k<=3;++k)
        {
            for(reg int j=0;j<10;++j){
                dp[i][0][k]+=dp[i-1][j][k];
            }
            for(reg int j=1;j<10;++j)
            {
                for(reg int p=0;p<10;++p)
                {
                    dp[i][j][k]+=dp[i-1][p][k-1];
                }
            }
        }
    }
}
ll query(const vector<int>& vec)
{
//    if(vec.size()==1&&vec[0]==0)return 0;
    ll ans=0;
    reg int cnt=0;
    for(reg int i=vec.size();i>0;--i)
    {
        for(reg int j=0;j<vec[i-1];++j)
        {
            for(reg int k=0;k<=3-cnt;++k)
            {
                ans+=dp[i][j][k];
            }
        }
        if(vec[i-1]) ++cnt;
        if(cnt>3) return ans;//ans-(i-1);
    }
    return ans;//ans-(vec.size()-1);
}
inline void trans(vector<int>& vec,const string& str)
{
    vec.clear();
    for(reg int i=str.size()-1;i>=0;--i)
    {
        vec.push_back(str[i]-'0');
    }
}
inline void add(vector<int>& vec)
{
    reg int t=1;
    for(reg int i=0,j=vec.size();i<j;++i)
    {
        vec[i]+=t;
        t=vec[i]/10;
        vec[i]%=10;
    }
    if(t)
        vec.push_back(t);
}
string l,r;
vector<int> lv,rv;
inline void solve()
{
    cin>>l>>r;
    trans(lv,l);
    trans(rv,r);
    add(rv);
    cout<<query(rv)-query(lv)<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);
    reg int t;
    cin>>t;
    n=19;
    init();
    while(t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
#define f(c,a,b) for(int c=a; c<=b; c++)

using namespace std;
typedef long long ll;
ll dp[20][5];  //第i位，前面有i个非0数字,这里存的是无限制的
int a[20];

ll swdp(int i, bool lim, int j){ //当前第i位，i+1位及以前已经有j个非0，lim=1表示有限制
    if(!i) return 1;
    if(!lim && dp[i][j]) return dp[i][j];
    int up = lim?a[i]:9;
    int ans=0;
    ans += swdp(i-1, lim&&a[i]==0, j);
    if(j<3 && up>1) ans += (up-1)*swdp(i-1, 0, j+1); //无限制部分
    if(j<3 && up>0) ans += swdp(i-1, lim, j+1);
    if(!lim) dp[i][j] = ans;
    return ans;
}

ll work(ll x){  //[0,x]
    int cnt = 0;
    while(x){ a[++cnt] = x%10; x/=10; }
    return swdp(cnt,1,0);
}

int main(){
    //freopen("owo.in","r",stdin);
    int t;
    cin >> t;
    ll l, r;
    while(t--){
        scanf("%lld%lld", &l, &r);
        printf("%lld\n", work(r)-work(l-1));
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int f[20][5];
int d[20];
int a,b;
int poi;
int dp(int v,int u,bool flag)
//v代表当前位,u代表非0的个数,flag判断是否越界
//从高位向低位搜，v递减
{
    if(v==0) return 1;//枚举完了
    if(!flag && f[v][u]!=-1)//优化步，如果不越界且这步已经搜完，直接返回搜的结果
    {
        return f[v][u];
    }

    int ans=0;
    int n;//结束标志
    if(flag)
        n=d[v];//如果当前枚举的数越界，也就是擦边，那么枚举到最大
    else
        n=9;//如果当前不擦边，就随便枚举
    for(int i=0; i<=n; i++)
    {
        if(i==0)
        {
            if(flag&&i==n)
                ans+=dp(v-1,u,1);
            else
                ans+=dp(v-1,u,0);
        }
        else if(u<3)
        {
            if(flag&&i==n)
                ans+=dp(v-1,u+1,1);
            else
                ans+=dp(v-1,u+1,0);
        }

    }
    if(!flag) f[v][u]=ans;//如果未越界，存入该位搜到u的结果
    return ans;
}
ll solve(int num)
{
    memset(f,-1,sizeof(f));
    int cnt=0;
    while(num)
    {
        d[++cnt]=num%10;//倒序存入数据各位
        num/=10;
    }
    return dp(cnt,0,1);//cnt为位数
}
int main()
{
    scanf("%d",&poi);
    while(poi--)
    {
        scanf("%d%d",&a,&b);
        printf("%lld\n",solve(b)-solve(a-1));
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
#define maxn 25
#define debug(x) cout<<(#x)<<" :"<<x<<endl
using namespace std;

string l,r;
int q;
ll c[maxn];
int w;
string us;
ll memo[maxn][5][5];

/*ll cmb(int n,int k)
{
	if(k>n) return 0;
	if(k==1) return n;
	if(k==2) return n*(n-1)/2;
}

void ini()
{
	for(int i=1;i<=20;i++)
	{
		c[i]=9+9*cmb(i-1,1)*9+9*cmb(i-1,2)*81;
	}
}*/

ll dfs(int cur,int m,int f)
{
	int v=0;
	if(cur>=w) return 1;
	if(memo[cur][m][f]!=-1) return memo[cur][m][f];
	if(f) v=us[cur]-'0';
	else v=9;
	ll ansn=0;
	for(int i=0;i<=v;i++)
	{
		if(i==0)
		{
		//	if(cur==0) continue;
		//	else
			{
				//if(i==v) ansn+=dfs(cur+1,m,1);
				//else ansn+=dfs(cur+1,m,0);
				//ansn+=dfs(cur+1,m,f&(i==v));
				if(f==1 && i==v)
				{
					ansn+=dfs(cur+1,m,1);
				}
				else if(f==1 && i!=v || f==0)
				{
					ansn+=dfs(cur+1,m,0);
				}
			}
		}
		else
		{
			if(m==3) continue;
		//	else
			{
				//ansn+=dfs(cur+1,m,f&(i==v));
				if(f==1 && i==v)
				{
					ansn+=dfs(cur+1,m,1);
				}
				else if(f==1 && i!=v || f==0)
				{
					ansn+=dfs(cur+1,m,0);
				}
				/*if(i==v)
				{
					ansn+=dfs(cur+1,m+1,1);
				}
				else
				{
					ansn+=dfs(cur+1,m+1,0);
				}*/
			}
		}
	}
	return memo[cur][m][f]=ansn;
}

ll slv(string x)
{
	//ll ans=0;
	us=x;
	w=x.length();
	memset(memo,-1,sizeof(memo));
	//for(int i=1;i<w;i++) ans+=c[i];
	//ans+=dfs(0,0,1);
	return dfs(0,0,1);
}

int chk(string x)
{
	int cnt=0;
	for(int i=0;i<x.length();i++)
	{
		if(x[i]!='0') cnt++;
	}
	return (cnt<=3);
}

int main(){
	cin>>q;
//	ini();
	while(q--)
	{
		cin>>l>>r;
		cout<<slv(r)-slv(l)+chk(l)<<endl;
	}
	return 0;
} #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
#define maxn 25
#define debug(x) cout<<(#x)<<" :"<<x<<endl
using namespace std;

string l,r;
int q;
ll c[maxn];
int w;
string us;
ll memo[maxn][5][5];

/*ll cmb(int n,int k)
{
	if(k>n) return 0;
	if(k==1) return n;
	if(k==2) return n*(n-1)/2;
}

void ini()
{
	for(int i=1;i<=20;i++)
	{
		c[i]=9+9*cmb(i-1,1)*9+9*cmb(i-1,2)*81;
	}
}*/

ll dfs(int cur,int m,int f)
{
	int v=0;
	if(cur>=w) return 1;
	if(memo[cur][m][f]!=-1) return memo[cur][m][f];
	if(f) v=us[cur]-'0';
	else v=9;
	ll ansn=0;
	for(int i=0;i<=v;i++)
	{
		if(i==0)
		{
		//	if(cur==0) continue;
		//	else
			{
				//if(i==v) ansn+=dfs(cur+1,m,1);
				//else ansn+=dfs(cur+1,m,0);
				//ansn+=dfs(cur+1,m,f&(i==v));
				if(f==1 && i==v)
				{
					ansn+=dfs(cur+1,m,1);
				}
				else
				{
					ansn+=dfs(cur+1,m,0);
				}
			}
		}
		else
		{
			if(m==3) continue;
		//	else
			{
				//ansn+=dfs(cur+1,m,f&(i==v));
				if(f==1 && i==v)
				{
					ansn+=dfs(cur+1,m,1);
				}
				else
				{
					ansn+=dfs(cur+1,m,0);
				}
				/*if(i==v)
				{
					ansn+=dfs(cur+1,m+1,1);
				}
				else
				{
					ansn+=dfs(cur+1,m+1,0);
				}*/
			}
		}
	}
	return memo[cur][m][f]=ansn;
}

ll slv(string x)
{
	//ll ans=0;
	us=x;
	w=x.length();
	memset(memo,-1,sizeof(memo));
	//for(int i=1;i<w;i++) ans+=c[i];
	//ans+=dfs(0,0,1);
	return dfs(0,0,1);
}

int chk(string x)
{
	int cnt=0;
	for(int i=0;i<x.length();i++)
	{
		if(x[i]!='0') cnt++;
	}
	return (cnt<=3);
}

int main(){
	cin>>q;
//	ini();
	while(q--)
	{
		cin>>l>>r;
		cout<<slv(r)-slv(l)+chk(l)<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int T,l[105],len;
long long L,R,tmp1,tmp2;
long long f[105][105][10];
void pre(long long x){
    len=0;
    while(x){
        l[++len]=x%10;
        x/=10;
    }
}

long long dp(int now,int cnt,bool lim){
    if(now==0) return 1;
    long long res=0;
    for(int i=0;i<=(now==len?l[now]:(lim?l[now]:9));i++){
        if(cnt+bool(i)>3) continue;
        if(!lim&&now!=len&&f[now][cnt][i]!=-1) {
            res+=f[now][cnt][i];continue;
        }
        long long tmp=dp(now-1,cnt+bool(i),((now==len||lim)&&l[now]==i));
        if(!lim&&now!=len) f[now][cnt][i]=tmp;
        res+=tmp;
    }
    return res;
}

int main(){
    scanf("%d",&T);
    memset(f,-1,sizeof(f));
    while(T--){
        scanf("%lld%lld",&L,&R);
        pre(L-1);tmp1=dp(len,0,0);
        pre(R);tmp2=dp(len,0,0);
        printf("%lld\n",tmp2-tmp1);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<int(upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L));
	}
}#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<int(upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L))<<endl;
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<int(upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L));
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<int(upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L))<<endl;
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000LL);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L);
	}
}#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<int(upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L));
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

vector<long long>num;

void init(int numindex,int cntindex,long long number)
{
	if(numindex==18)
	{
		num.push_back(number);
		return;
	}
	init(numindex+1,cntindex,number*10);
	if(cntindex<3)
		for(int i=1; i<=9; i++)
			init(numindex+1,cntindex+1,number*10+i);
}

int main()
{
	cin.tie(0);
	init(0,0,0);
	num.push_back(1000000000000000000LL);
	int T;
	cin>>T;
	for(int t=1;t<=T;t++)
	{
		long long L,R;
		cin>>L>>R;
		cout<<upper_bound(num.begin(),num.end(),R)-lower_bound(num.begin(),num.end(),L);
	}
}


#include<iostream>
#include<string>
//#include<basic_string>
#include <bits/stdc++.h>
#include<cstring>

using namespace std;
#define ll long long int

ll dp[19][4][2];
string s;
ll solve(ll i,ll cnt,ll f){
    if(cnt>3){return 0;}
    if(i==s.size()){
        return 1;
    }
    ll ans=0;
    if(dp[i][cnt][f]!=-1){return dp[i][cnt][f];}

    for(ll j=0;j<10;j++){
        if(j<s[i]-'0'){
        ans+=solve(i+1,cnt+!!j,1);}
        else if(f || s[i]-'0'==j){ans+=solve(i+1,cnt+!!j,f);}
    }
    dp[i][cnt][f]=ans;
    return dp[i][cnt][f];
}

int main()
{
    ll n;
    cin>>n;

    for(ll i=0;i<n;i++){
        ll l,r;
        cin>>l>>r;
        l--;
        s=to_string(r);
        ll ans=0;
        memset(dp,-1,sizeof(dp));
        ans+=solve(0,0,0);
       // for(ll i=0;i<s.size();i++){cout<<dp[i][]}
        memset(dp,-1,sizeof(dp));
        s=to_string(l);
        ans-=solve(0,0,0);
        cout<<ans<<'\n';
    }
}


#include<iostream>
#include<string>
//#include<basic_string>
#include <bits/stdc++.h>
#include<cstring>

using namespace std;
#define ll long long int

int dp[19][4][2];
string s;
int solve(ll i,ll cnt,ll f){
    if(cnt>3){return 0;}
    if(i==s.size()){
        return 1;
    }
    int ans=0;
    if(dp[i][cnt][f]!=-1){return dp[i][cnt][f];}

    for(ll j=0;j<10;j++){
        if(j<s[i]-'0'){
        ans+=solve(i+1,cnt+!!j,1);}
        else if(f || s[i]==j){ans+=solve(i+1,cnt+!!j,f);}
    }
    dp[i][cnt][f]=ans;
    return dp[i][cnt][f];
}

int main()
{
    ll n;
    cin>>n;

    for(ll i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        l--;
        s=to_string(r);
        int ans=0;
        memset(dp,-1,sizeof(dp));
        ans+=solve(0,0,0);
       // for(int i=0;i<s.size();i++){cout<<dp[i][]}
        memset(dp,-1,sizeof(dp));
        s=to_string(l);
        ans-=solve(0,0,0);
        cout<<ans<<'\n';
    }
}


#include<iostream>
#include<string>
//#include<basic_string>
#include <bits/stdc++.h>
#include<cstring>

using namespace std;
#define ll long long int

ll dp[20][5][2];
string s;
ll solve(ll i,ll cnt,ll f){
    if(cnt>3){return 0;}
    if(i==s.size()){
        return 1;
    }
    ll ans=0;
    if(dp[i][cnt][f]!=-1){return dp[i][cnt][f];}

    for(ll j=0;j<10;j++){
        if(j<s[i]-'0'){
        ans+=solve(i+1,cnt+!!j,1);}
        else if(f || s[i]-'0'==j){ans+=solve(i+1,cnt+!!j,f);}
    }
    dp[i][cnt][f]=ans;
    return dp[i][cnt][f];
}

int main()
{
    ll n;
    cin>>n;

    for(ll i=0;i<n;i++){
        ll l,r;
        cin>>l>>r;
        l--;
        s=to_string(r);
        ll ans=0;
        memset(dp,-1,sizeof(dp));
        ans+=solve(0,0,0);
       // for(ll i=0;i<s.size();i++){cout<<dp[i][]}
        memset(dp,-1,sizeof(dp));
        s=to_string(l);
        ans-=solve(0,0,0);
        cout<<ans<<'\n';
    }
}


#include<iostream>
#include<string>
//#include<basic_string>
#include <bits/stdc++.h>
#include<cstring>

using namespace std;
#define ll long long int

int dp[19][4][2];
string s;
int solve(ll i,ll cnt,ll f){
    if(cnt>3){return 0;}
    if(i==s.size()){
        return 1;
    }
    int ans=0;
    if(dp[i][cnt][f]!=-1){return dp[i][cnt][f];}

    for(ll j=0;j<10;j++){
        if(j<s[i]-'0'){
        ans+=solve(i+1,cnt+!!j,1);}
        else if(f || s[i]-'0'==j){ans+=solve(i+1,cnt+!!j,f);}
    }
    dp[i][cnt][f]=ans;
    return dp[i][cnt][f];
}

int main()
{
    ll n;
    cin>>n;

    for(ll i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        l--;
        s=to_string(r);
        int ans=0;
        memset(dp,-1,sizeof(dp));
        ans+=solve(0,0,0);
       // for(int i=0;i<s.size();i++){cout<<dp[i][]}
        memset(dp,-1,sizeof(dp));
        s=to_string(l);
        ans-=solve(0,0,0);
        cout<<ans<<'\n';
    }
}


#include<iostream>
#include<string>
//#include<basic_string>
#include <bits/stdc++.h>
#include<cstring>

using namespace std;
#define ll long long int

int dp[20][5][2];
string s;
int solve(ll i,ll cnt,ll f){
    if(cnt>3){return 0;}
    if(i==s.size()){
        return 1;
    }
    int ans=0;
    if(dp[i][cnt][f]!=-1){return dp[i][cnt][f];}

    for(ll j=0;j<10;j++){
        if(j<s[i]-'0'){
        ans+=solve(i+1,cnt+!!j,1);}
        else if(f || s[i]-'0'==j){ans+=solve(i+1,cnt+!!j,f);}
    }
    dp[i][cnt][f]=ans;
    return dp[i][cnt][f];
}

int main()
{
    ll n;
    cin>>n;

    for(ll i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        l--;
        s=to_string(r);
        int ans=0;
        memset(dp,-1,sizeof(dp));
        ans+=solve(0,0,0);
       // for(int i=0;i<s.size();i++){cout<<dp[i][]}
        memset(dp,-1,sizeof(dp));
        s=to_string(l);
        ans-=solve(0,0,0);
        cout<<ans<<'\n';
    }
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
map<int,int> mem;
int count(int x)
{
	if(x==0) return 0;
	if(mem[x]) return mem[x];
	int ans=0;
	int t=x,cnt=0;
	while(t)
	{
		cnt++;
		t/=10;
	}
	//one
	for(int i=1;i<=cnt;i++)
		for(int j=1;j<=9;j++)
		{
			int cur=0;
			for(int k=1;k<=cnt;k++)
				if(k!=i)
					cur*=10;
				else
					cur=cur*10+j;
			if(cur<=x) ans++;
		}
	//two
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt;j++)
			for(int a=1;a<=9;a++)
				for(int b=1;b<=9;b++)
				{
					int cur=0;
					for(int k=1;k<=cnt;k++)
						if(k==i)
							cur=cur*10+a;
						else if(k==j)
							cur=cur*10+b;
						else
							cur*=10;
					if(cur<=x) ans++;
				}
	//three
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt;j++)
			for(int k=j+1;k<=cnt;k++)
					for(int a=1;a<=9;a++)
						for(int b=1;b<=9;b++)
							for(int c=1;c<=9;c++)
							{
								int cur=0;
								for(int id=1;id<=cnt;id++)
									if(id==i)
										cur=cur*10+a;
									else if(id==j)
										cur=cur*10+b;
									else if(id==k)
										cur=cur*10+c;
									else
										cur*=10;
								if(cur<=x) ans++;
							}
	mem[x]=ans;
	return ans;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		int l,r;
		cin>>l>>r;
		cout<<count(r)-count(l-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int count(int x)
{
	if(x==0) return 1;
	vector<int> v;
	while(x)
	{
		v.push_back(x%10);
		x/=10;
	}
	int ans=0,cnt=0;
	for(int i=v.size()-1;i>=0;i--)
	{
		for(int j=0;j<=v[i]-1;j++)
		{
			if(j!=0) cnt++;
			if(cnt==0)
				ans+=(1+i*9+i*(i>=1?i-1:0)/2*81+i*(i>=1?i-1:0)*(i>=2?i-2:0)/6*729);
			else if(cnt==1)
				ans+=(1+i*9+i*(i>=1?i-1:0)/2*81);
			else if(cnt==2)
				ans+=(1+i*9);
			else if(cnt==3)
				ans++;
			if(j!=0) cnt--;
		}
		if(v[i]!=0)
			cnt++;
		if(cnt>3) break;
	}
	if(cnt<=3) ans++;
	return ans;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		int l,r;
		cin>>l>>r;
		cout<<count(r)-count(l-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int count(int x)
{
	if(x==0) return 0;
	int ans=0;
	int t=x,cnt=0;
	while(t)
	{
		cnt++;
		t/=10;
	}
	//one
	for(int i=1;i<=cnt;i++)
		for(int j=1;j<=9;j++)
		{
			int cur=0;
			for(int k=1;k<=cnt;k++)
				if(k!=i)
					cur*=10;
				else
					cur=cur*10+j;
			if(cur<=x) ans++;
		}
	//two
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt;j++)
			for(int a=1;a<=9;a++)
				for(int b=1;b<=9;b++)
				{
					int cur=0;
					for(int k=1;k<=cnt;k++)
						if(k==i)
							cur=cur*10+a;
						else if(k==j)
							cur=cur*10+b;
						else
							cur*=10;
					if(cur<=x) ans++;
				}
	//three
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt;j++)
			for(int k=j+1;k<=cnt;k++)
					for(int a=1;a<=9;a++)
						for(int b=1;b<=9;b++)
							for(int c=1;c<=9;c++)
							{
								int cur=0;
								for(int id=1;id<=cnt;id++)
									if(id==i)
										cur=cur*10+a;
									else if(id==j)
										cur=cur*10+b;
									else if(id==k)
										cur=cur*10+c;
									else
										cur*=10;
								if(cur<=x) ans++;
							}
	return ans;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		int l,r;
		cin>>l>>r;
		cout<<count(r)-count(l-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int unsigned long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
map<int,int> mem;
int count(int x)
{
	if(x==0) return 0;
	if(mem[x]) return mem[x];
	int ans=0;
	int t=x,cnt=0;
	while(t)
	{
		cnt++;
		t/=10;
	}
	//one
	for(int i=1;i<=cnt;i++)
		for(int j=1;j<=9;j++)
		{
			int cur=0;
			for(int k=1;k<=cnt;k++)
				if(k!=i)
					cur*=10;
				else
					cur=cur*10+j;
			if(cur<=x) ans++;
		}
	//two
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt;j++)
			for(int a=1;a<=9;a++)
				for(int b=1;b<=9;b++)
				{
					int cur=0;
					for(int k=1;k<=cnt;k++)
						if(k==i)
							cur=cur*10+a;
						else if(k==j)
							cur=cur*10+b;
						else
							cur*=10;
					if(cur<=x) ans++;
				}
	//three
	for(int i=1;i<=cnt;i++)
		for(int j=i+1;j<=cnt;j++)
			for(int k=j+1;k<=cnt;k++)
					for(int a=1;a<=9;a++)
						for(int b=1;b<=9;b++)
							for(int c=1;c<=9;c++)
							{
								int cur=0;
								for(int id=1;id<=cnt;id++)
									if(id==i)
										cur=cur*10+a;
									else if(id==j)
										cur=cur*10+b;
									else if(id==k)
										cur=cur*10+c;
									else
										cur*=10;
								if(cur<=x) ans++;
							}
	mem[x]=ans;
	return ans;
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		int l,r;
		cin>>l>>r;
		cout<<count(r)-count(l-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int count(int x)
{
	if(x==0) return 0;
	set<int> st;
	int t=x,cnt=0;
	while(t)
	{
		cnt++;
		t/=10;
	}
	//one
	for(int i=1;i<=cnt;i++)
		for(int j=1;j<=9;j++)
		{
			int cur=0;
			for(int k=1;k<=cnt;k++)
				if(k!=i)
					cur*=10;
				else
					cur=cur*10+j;
			if(cur<=x) st.insert(cur);
		}
	//two
	for(int i=1;i<=cnt;i++)
		for(int j=1;j<=cnt;j++)
			if(i!=j)
				for(int a=1;a<=9;a++)
					for(int b=1;b<=9;b++)
					{
						int cur=0;
						for(int k=1;k<=cnt;k++)
							if(k==i)
								cur=cur*10+a;
							else if(k==j)
								cur=cur*10+b;
							else
								cur*=10;
						if(cur<=x) st.insert(cur);
					}
	//three
	for(int i=1;i<=cnt;i++)
		for(int j=1;j<=cnt;j++)
			if(i!=j)
				for(int k=1;k<=cnt;k++)
					if(i!=k&&j!=k)
						for(int a=1;a<=9;a++)
							for(int b=1;b<=9;b++)
								for(int c=1;c<=9;c++)
								{
									int cur=0;
									for(int id=1;id<=cnt;id++)
										if(id==i)
											cur=cur*10+a;
										else if(id==j)
											cur=cur*10+b;
										else if(id==k)
											cur=cur*10+c;
										else
											cur*=10;
									if(cur<=x) st.insert(cur);
								}
	return st.size();
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int tc=1;tc<=t;tc++)
	{
		int l,r;
		cin>>l>>r;
		cout<<count(r)-count(l-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll d[20][4];
int a[20];
ll dfs(int pos, int num, int lead, int limit) {
    if (pos == 0)   return 1;
    if (!lead && !limit && d[pos][num] != -1) {
        return d[pos][num];
    }
    ll ret = 0;
    int up = limit ? a[pos] : 9;
    for (int i = 0; i <= up; i++) {
        if (num == 3 && i)  continue;
        ret += dfs(pos - 1, num + (i > 0), lead && i == 0, limit && i == a[pos]);
    }
    if (!lead && !limit)    d[pos][num] = ret;
    return ret;
}
ll f(ll x) {
    int p = 0;
    while (x) {
        a[++p] = x % 10;
        x /= 10;
    }
    return dfs(p, 0, 0, 1);
}
int main() {
    memset(d, -1, sizeof d);
    int T;
    scanf("%d", &T);
    while (T--) {
        ll l, r;
        scanf("%I64d%I64d", &l, &r);
        printf("%I64d\n", f(r) - f(l - 1));
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll d[20][4];
int a[20];
ll dfs(int pos, int num, int lead, int limit) {
    if (pos == 0)   return 1;
    if (!lead && !limit && d[pos][num] != -1) {
        return d[pos][num];
    }
    ll ret = 0;
    int up = limit ? a[pos] : 9;
    for (int i = 0; i <= up; i++) {
        if (num == 3 && i)  continue;
        ret += dfs(pos - 1, num + (i > 0), lead && i == 0, limit && i == a[pos]);
    }
    if (!lead && !limit)    d[pos][num] = ret;
    return ret;
}
ll f(ll x) {
    int p = 0;
    while (x) {
        a[++p] = x % 10;
        x /= 10;
    }
    printf("p = %d\n", p);
    return dfs(p, 0, 0, 1);
}
int main() {
    memset(d, -1, sizeof d);
    int T;
    scanf("%d", &T);
    while (T--) {
        ll l, r;
        scanf("%I64d%I64d", &l, &r);
        printf("%I64d\n", f(r) - f(l - 1));
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll d[20][4];
int a[20];
ll dfs(int pos, int num, int lead, int limit) {
    if (pos == 0)   return 1;
    if (!lead && !limit && d[pos][num] != -1) {
        return d[pos][num];
    }
    ll ret = 0;
    int up = limit ? a[pos] : 9;
    for (int i = 0; i <= up; i++) {
        if (num == 3 && i)  continue;
        ret += dfs(pos - 1, num + (i > 0), lead && i == 0, limit && i == a[pos]);
    }
    if (!lead && !limit)    d[pos][num] = ret;
    return ret;
}
ll f(int x) {
    int p = 0;
    while (x) {
        a[++p] = x % 10;
        x /= 10;
    }
    return dfs(p, 0, 0, 1);
}
int main() {
    memset(d, -1, sizeof d);
    int T;
    scanf("%d", &T);
    while (T--) {
        ll l, r;
        scanf("%I64d%I64d", &l, &r);
        printf("%I64d\n", f(r) - f(l - 1));
    }
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 20;
const int maxm = 5;
int a[maxn];
ll d[maxn][maxm];
ll dfs(int pos, int num, int limit) {
    if (pos == 0)   return 1;
    if (!limit && d[pos][num] != -1) {
        return d[pos][num];
    }
    ll ret = 0;
    int up = limit ? a[pos] : 9;
    for (int i = 0; i <= up; i++) {
        if (num == 3 && i)  continue;
        ret += dfs(pos - 1, num + (i > 0), limit && i == a[pos]);
    }
    if (!limit) d[pos][num] = ret;
    return ret;
}
ll f(ll x) {
    int p = 0;
    while (x) {
        a[++p] = x % 10;
        x /= 10;
    }
    return dfs(p, 0, 1);
}
int main() {
    memset(d, -1, sizeof d);
    int T;
    scanf("%d", &T);
    while (T--) {
        ll l, r;
        scanf("%I64d%I64d", &l, &r);
        printf("%I64d\n", f(r) - f(l - 1));
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll d[20][4];
int a[20];
ll dfs(int pos, int num, int lead, int limit) {
    if (pos == 0) {
        if (lead)   return 0;
        return 1;
    }
    if (!lead && !limit && d[pos][num] != -1) {
        return d[pos][num];
    }
    ll ret = 0;
    int up = limit ? a[pos] : 9;
    for (int i = 0; i <= up; i++) {
        if (num == 3 && i > 0)  continue;
        ret += dfs(pos - 1, num + (i > 0), lead && i == 0, limit && i == a[pos]);
    }
    if (!lead && !limit)    d[pos][num] = ret;
    return ret;
}
ll f(int x) {
    int p = 0;
    while (x) {
        a[++p] = x % 10;
        x /= 10;
    }
    return dfs(p, 0, 0, 1);
}
int main() {
    memset(d, -1, sizeof d);
    int T;
    scanf("%d", &T);
    while (T--) {
        ll l, r;
        scanf("%I64d%I64d", &l, &r);
        printf("%I64d\n", f(r) - f(l - 1));
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll d[20][4];
int a[20];
ll dfs(int pos, int num, int lead, int limit) {
    if (pos == 0)   return lead;
    if (!lead && !limit && d[pos][num] != -1) {
        return d[pos][num];
    }
    ll ret = 0;
    int up = limit ? a[pos] : 9;
    for (int i = 0; i <= up; i++) {
        if (num == 3 && i)  continue;
        ret += dfs(pos - 1, num + (i > 0), lead && i == 0, limit && i == a[pos]);
    }
    if (!lead && !limit)    d[pos][num] = ret;
    return ret;
}
ll f(int x) {
    int p = 0;
    while (x) {
        a[++p] = x % 10;
        x /= 10;
    }
    return dfs(p, 0, 0, 1);
}
int main() {
    memset(d, -1, sizeof d);
    int T;
    scanf("%d", &T);
    while (T--) {
        ll l, r;
        scanf("%I64d%I64d", &l, &r);
        printf("%I64d\n", f(r) - f(l - 1));
    }
    return 0;
}


#include<bits/stdc++.h>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();num=0;T f=1;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
int dp1[20][4][2];int dp2[20][4][2];
int fdp1[20];int fdp2[20];
inline int dp(int len,int count,int tmp,int limi){
	if(count>3)return 0;
	if(!len)return 1;
	int num=0;
	if(tmp==1){
		if(dp1[len][count][limi]!=-1)return dp1[len][count][limi];
		num=(limi)?fdp1[len]:9;
	}else{
		if(dp2[len][count][limi]!=-1)return dp2[len][count][limi];
		num=(limi)?fdp2[len]:9;
	}

	int re_value=0;
	rep(i,0,num){
		re_value+=dp(len-1,count+(i!=0),tmp,(limi&&i==num));
	}
	if(tmp==1){
		dp1[len][count][limi]=re_value;
	}else{
		dp2[len][count][limi]=re_value;
	}
	return re_value;
}

int main(){
	int T;read(T);
	while(T){
		T--;
		long long li,ri;read(li);read(ri);
		int len1,len2;len1=len2=0;li--;
		while(li){
			fdp1[++len1]=li%10;li/=10;
		}
		while(ri){
			fdp2[++len2]=ri%10;ri/=10;
		}

		memset(dp1,-1,sizeof(dp1));memset(dp2,-1,sizeof(dp2));
		long long nop1=dp(len1,0,1,1);
		long long nop2=dp(len2,0,2,1);
		write(nop2-nop1);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<set>
#include<map>
using namespace std;
#define ll long long
long long L,R,ans,b[10];
int a[22],n;
ll C(int n,int m)
{
    if(m>n) return 0;
    ll tmp=1;
    for(int i=1;i<=m;i++)
        tmp*=(n-i+1);
    for(int i=1;i<=m;i++)
        tmp/=i;
    return tmp;
}
void cal(int n,int sum)
{
    if(n==0)
    {
        if(sum<=3) ans++;
        return;
    }
    for(int i=0;i<a[n];i++)
    {
        for(int j=0;j<=3-sum-(i!=0);j++)
            ans+=C(n-1,j)*b[j];
    }
    cal(n-1,sum+(a[n]!=0));
}
long long solve(ll x)
{
    //cout << x <<" ";
    n=0;
    while(x)
    {
        a[++n]=x%10;
        x/=10;
    }
    ans=0;
    cal(n,0);
    //cout << ans << endl;
    return ans;

}
int main()
{
    b[0]=1; b[1]=9; b[2]=81; b[3]=81*9;
    int T;
    cin >> T;
    while(T--)
    {
        cin >> L >> R;
        cout << solve(R)-solve(L-1) << endl;
    }
    return 0;
}


#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
int t;
string l,r;
string s;
int len;
long long memo[50][10][10];
long long dfs(int cur,int m,bool f){
    //cout<<"??"<<cur<<endl;
    if(cur==len)return 1;
    if(memo[cur][m][f]!=-1)return memo[cur][m][f];
    else{
        int v;
        if(f)v=s[cur]-'0';
        else v=9;
        long long ans=0;
        for(int i=0;i<=v;i++){
            if(i==0)ans+=dfs(cur+1,m,f&(i==(s[cur]-'0')));
            else{
                if(m==3)continue;
                else ans+=dfs(cur+1,m+1,f&(i==(s[cur]-'0')));
            }
        }
        //cout<<"???"<<ans<<endl;
        //cout<<ans<<endl;
        return memo[cur][m][f]=ans;
    }
}
long long solve(string& x){
    memset(memo,-1,sizeof(memo));
    s=x;
    len=s.length();
    return dfs(0,0,1);
}
bool chk(string x){
    int cnt=0;
    for(int i=0;i<x.length();i++){
        //cout<<"????????"<<x[i]<<endl;
        if(x[i]-'0'!=0)cnt++;
    }
    //cout<<"???"<<x<<" "<<cnt<<endl;
    if(cnt<=3)return 1;
    else return 0;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>t;
	while(t--){
	    cin>>l>>r;
	    //cout<<"???"<<solve(r)<<endl;
	    cout<<solve(r)-solve(l)+chk(l)<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
long long t,l,r,p;
int s,s1;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>l>>r;
		s1=0;
		for(long long i=l;i<=r;i++)
		{
			p=i;
			s=0;
			while(p)
			{
				if(p%10!=0)
				{
					s++;
				}
				p/=10;
				if(s>3)
				break;
			}
			if(s<=3)
			s1++;
		}
		cout<<s1<<endl;
	}
}


#include <iostream>
#include <cstring>
#include <string>

using namespace std;

int N;
string s;

int memo[20][4][2];

long long dfs(int n, int m, int flag)
{
    if(n == N)  return 1;
    if(memo[n][m][flag] != -1)  return memo[n][m][flag];
    long long ans = 0;
    int maxnum = 9;
    if(flag == 1)   maxnum = s[n] - '0';

    for(int i = 0; i <= maxnum; i++)
    {
        if(i == 0)  ans += dfs(n + 1, m, flag&(i == maxnum));
        else if(m < 3)   ans += dfs(n + 1, m + 1, flag&(i == maxnum));
    }
    return memo[n][m][flag] = ans;
}

long long solve(string toSolve)
{
    s = toSolve;
    N = s.length();
    memset(memo, -1, sizeof(memo));
    return dfs(0, 0, 1);
}

int check(string toSolve)
{
    int cnt = 0;
    for(int i = 0; i < toSolve.length(); i++)
    {
        if(toSolve[i] != '0') cnt++;
    }
    if(cnt > 3) return 0;
    return 1;
}

int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        string a, b;
        cin >> a >> b;
        cout << solve(b) - solve(a) + check(a) << endl;
    }
    return 0;
}

//wtf error？？？？？


#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a[20], dp[20][5], l, r;
ll dfs(ll pos, ll st, bool limit) {
    if(pos == -1) return 1;
    if(!limit && dp[pos][st] != -1) return dp[pos][st];
    ll up = (limit ? a[pos] : 9), ans = 0;
    for(ll i = 0; i <= up; i++) {
        if(i == 0) ans += dfs(pos-1, st, limit && a[pos] == i);
        else if(st != 3) ans += dfs(pos-1, st+1, limit && a[pos] == i);
    }
    if(!limit) dp[pos][st] = ans;
    return ans;
}
ll work(ll x) {
    ll tot = 0;
    while(x > 0) {
        a[tot++] = x % 10;
        x /= 10;
    }
    return dfs(tot-1, 0, true);
}
int main() {
    memset(dp, -1, sizeof(dp)); int T;
    scanf("%d", &T);
    while(T--) {
        scanf("%lld %lld", &l, &r);
        printf("%lld\n", work(r) - work(l-1));
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int a[21],dp[21][11];
ll dfs(int pos,int num,bool limit)
{
	if(pos==-1) return 1;
	if(!limit&&dp[pos][num]!=-1) return dp[pos][num];
	if(num>=3) return dp[pos][num]=1;
	ll sum=0;
	int up=limit? a[pos]:9;
	for(int i=0;i<=up;i++)
	{
		if(i==0) sum+=dfs(pos-1,num,limit&&i==a[pos]);
		else sum+=dfs(pos-1,num+1,limit&&i==a[pos]);
	}
	if(!limit) dp[pos][num]=sum;
	return sum;
}
ll solve(ll x)
{
	int pos=0;
	while(x)
	{
		a[pos++]=x%10;
		x/=10;
	}
	return dfs(pos-1,0,true);
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		memset(dp,-1,sizeof(dp));
		ll left;
		ll right;
		scanf("%lld%lld",&left,&right);
		printf("%lld\n",solve(right)-solve(left-1));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans[200][1700];
int n,a[220],tt=0;
long long dp(int eq,int dep,int l,int t){
	if(!dep||t==3) return 1;
	if(!eq&&l&&~ans[dep][t]) return ans[dep][t];
	int ed=(eq)?a[dep]:9;
	long long ret=0;
	for(int i=0;i<=ed;i++){
		ret+=dp(eq&&(i==ed),dep-1,l||i,t+bool(i));
	}
	if(!eq&&l) ans[dep][t]=ret;
	return ret;
}
long long work(long long n){
	a[0]=0;
	for(;n;n/=10) a[++a[0]]=n%10;
	memset(ans,-1,sizeof(ans));
	return dp(1,a[0],0,0);
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
    	long long L,R;
	    cin>>L>>R;
		cout<<work(R)-work(L-1)<<endl;
	}
	return 0;
}


#include <cstdio>
#include <cstring>
#define re register

using namespace std;

#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))

inline ll read(){
	ll f=1,r=0;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9')r=(r<<1)+(r<<3)+(c^48),c=getchar();
	return r*f;
}

int len,a[19];
ll f[20][5];
//
ll dfs(int pos,int sum,int limit){
	if(!pos){
		if(sum<=3) return 1;
		return 0;
	}
	if(sum>3) return 0;
	if(!limit && f[pos][sum]^-1) return f[pos][sum];
	int high=limit?a[pos]:9;ll ans=0;
	for(re int i=0;i<=high;i++){
		if(!i) ans+=dfs(pos-1,sum,i==high && limit);
		else ans+=dfs(pos-1,sum+1,i==high && limit);
	}
	if(!limit) f[pos][sum]=ans;
	return ans;
}

inline ll div(ll x){
	len=0;
	while(x) a[++len]=x%10,x/=10;
	mem(f,-1);return dfs(len,0,1);
}

int main(){
	int T=read();
	while(T--){
		ll x=read(),y=read();
		printf("%lld\n",div(y)-div(x-1));
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define ll long long
#define ri register int

using namespace std;

inline void read(int &x)
{
	x = 0;
	bool f = 0;
	char ch = getchar();
	while(!isdigit(ch)) f = ch  == '-', ch = getchar();
	while(isdigit(ch)) x = (x<<3)+(x<<1)+ch-48, ch = getchar();
	if(f) x = -x;
}

int T, a[25];
ll l, r;
ll dp[10][25];

ll dfs(int pos, int cnt, bool limit)
{
	if(cnt > 3) return 0;
	if(pos == -1) return 1;
	if(!limit && dp[pos][cnt] != -1) return dp[pos][cnt];

	ll tmp = 0, up = limit?a[pos]:9;

	for(ri i = 0; i <= up; i++)
		tmp += dfs(pos-1, limit&&(i == up), cnt + (i>0));

	return dp[pos][cnt] = tmp;
}

ll solve(int x)
{
	 memset(dp, -1, sizeof(dp));
	 int t = 0;
	 for(; x; a[t++] = x%10, x /= 10);
	 return dfs(t-1, 1, 0);
}

void work()
{
	cin >> l >> r;
	printf("%I64d\n", solve(r) - solve(l-1));
}

int main()
{
	read(T);
	while(T--) work();
	return 0;
}


#include <iostream>
#include <cstdio>
using namespace std;
int T,l[105],len;
long long L,R,tmp1,tmp2;
void pre(long long x){
    len=0;
    while(x){
        l[++len]=x%10;
        x/=10;
    }
}

long long dp(int now,int cnt,bool lim){
    if(now==0) return 1;
    long long res=0;
    for(int i=0;i<=(now==len?l[now]:(lim?l[now]:9));i++){
        if(cnt+bool(i)>3) continue;
        res+=dp(now-1,cnt+bool(i),((now==len||lim)&&l[now]==i));
    }
    return res;
}

int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%lld%lld",&L,&R);
        pre(L-1);tmp1=dp(len,0,0);
        pre(R);tmp2=dp(len,0,0);
        printf("%lld\n",tmp2-tmp1);
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long
using namespace std;
int n,b[20];
LL dp[20][5];
LL dfs(LL now,LL start,bool limit)
{
	if(now==-1)
		return 1;
	if(!limit&&dp[now][start]!=-1)
		return dp[now][start];
    LL up=limit?b[now]:9;
	LL ans=0;
    for(LL i=0;i<=up;i++)
    {
        if(i==0)
			ans+=dfs(now-1,start,limit&&b[now]==i);
        else
			if(start!=3)
				ans+=dfs(now-1,start+1,(limit&&b[now])==i);
    }
    if(!limit)
		dp[now][start]=ans;
    return ans;
}
LL find(LL x)
{
	int ss=0;
	while(x>0)
	{
		b[ss++]=x%10;
		x/=10;
	}
	return dfs(ss-1,0,true);
}
int main()
{
	//freopen("miracle.in","r",stdin);
	//freopen("miracle.out","w",stdout);
	memset(dp,-1,sizeof dp);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		LL l,r;
		scanf("%d%d",&l,&r);
		printf("%d\n",find(r)-find(l-1));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long LL;
struct S{
    LL f[10][25],a[25];
    LL dfs(LL pos,LL limit,LL cnt){
        if(cnt>3) return 0;
        if(pos==-1) return 1;
        if(!limit&&f[pos][cnt]!=-1) return f[pos][cnt];
        LL tmp=0,Up= limit? a[pos]:9;
        for(int i=0;i<=Up;i++) tmp+=dfs(pos-1,limit&&(i==Up),cnt+(i>0));
        if(!limit) f[pos][cnt] = tmp;
        return tmp;
    }
    LL solve(LL x){
        memset(f,-1,sizeof(f));
        LL pos=0;
        while(x){ a[pos++]=x%10; x/=10; }
        return dfs(pos-1,1,0);
    }
}S;
LL T,n,m,s,k,l,r;
int main(){
    scanf("%lld",&T);
    //S.a (f, -1, sizeof (f));
    while(T--){
        scanf("%lld%lld",&l,&r);
        printf("%lld\n",S.solve(r)-S.solve(l-1));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long long t;
	bool pd(int n);
	cin >> t;
	long long n,m,sum;
	for(int qwe=1;qwe<=t;qwe++)
	{
		int flag=0;
		sum=0;
		cin >> n >> m;
		for(int i=n;i<=m;i++)
		{
			if(pd(i))
			{
				sum++;
			}
		}
		cout << sum << endl;
	}
	return 0;
}
bool pd(int n)
{
	stringstream ss;
	int tt=0;
	ss << n;
	string s;
	ss >> s;
	for(int i=0;i<=s.size()-1;i++)
		if(s[i]!='0')
		{
			tt++;
		}
		if(tt>3) return false;
	return true;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define lson root<<1
#define rson root<<1|1
const int INF = 0x3f3f3f3f;
const int MAXN = 2005;
const int MOD = 1e9+7;
const double PI = acos(-1);
LL dp[30][5];
int dight[30];
LL dfs(int pos,int sta,bool lead,bool limit){
    if(pos==-1) return sta<=3;
    if(!limit && !lead && dp[pos][sta]!=-1) return dp[pos][sta];
    LL res = 0;
    int up = limit ? dight[pos]:9;
    for(int i=0;i<=up;i++){
        res += dfs(pos-1,i==0 ? sta:sta+1,lead && i==0,limit && i==up);
    }
    if(!limit && !lead)
        dp[pos][sta]=res;
    return res;
}
LL solve(LL x){
    int pos = 0;
    while(x){
        dight[pos++] = x%10;
        x /= 10;
    }
    return dfs(pos-1,0,1,1);
}
int main(){
    int T;
    LL l,r;
    memset(dp,-1,sizeof(dp));
    cin>>T;
    while(T--){
        cin>>l>>r;
        cout<<solve(r)-solve(l-1)<<endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define LL long long
LL a[30],dp[30][4];

LL DFS(int pos,int Count,bool limit){
	if(pos==-1){
		if(Count<=3) return 1;
		else return 0;
	}
	if(!limit && dp[pos][Count]!=-1) return dp[pos][Count];
	int up=limit?a[pos]:9;
	LL Ans=0;
	for(register int i=0;i<=up;++i){
		if(i==0 && Count<=3) Ans+=DFS(pos-1,Count,limit && i==a[pos]);
		else if(Count<=2) Ans+=DFS(pos-1,Count+1,limit && i==a[pos]);
	}
	if(!limit) dp[pos][Count]=Ans;
	return Ans;
}

LL Solve(LL x){
	int pos=0;
	while(x){a[pos++]=x%10LL;x/=10LL;}
	return DFS(pos-1,0,true);
}

int main(){
	memset(dp,-1,sizeof(dp));
	int T;
	scanf("%d",&T);
	while(T--){
		LL L,R;
		scanf("%I64d%I64d",&L,&R);
		printf("%I64d\n",Solve(R)-Solve(L-1));
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long dp[20][5][2];
int t;
long long dfs(int cur,int s,string r,int limit)
{
	if(s>3) return 0;
	if(cur==r.length()+1) return 1;
	long long res;
	if(limit==1)
		res=dfs(cur+1,s,r,1)+9*dfs(cur+1,s+1,r,1);
	else
	{
		res=dfs(cur+1,s,r,(0<(r[cur-1]-'0')));
		if(r[cur-1]-'0'!=0) res+=dfs(cur+1,s+1,r,0);
		if(r[cur-1]-'0'>1) res+=(r[cur-1]-'0'-1)*dfs(cur+1,s+1,r,1);
	}

//	cout<<cur<<" "<<s<<" "<<limit<<": ";
//	cout<<res<<endl;
	return res;
}
int main()
{
	cin>>t;
	while(t--)
	{
		long long l1,r1;
		string l,r;
		cin>>l1>>r1;
		while(r1)
		{
			r.insert(0,1,'0'+r1%10);
			r1/=10;
		}
		if(l1==0) cout<<dfs(1,0,r,0);
		else
		{
			l1--;
			if(l1==0) l.insert(0,1,'0');
			while(l1)
			{
				l.insert(0,1,'0'+l1%10);
				l1/=10;
			}
	//		cout<<l<<" "<<r<<endl;
			cout<<dfs(1,0,r,0)-dfs(1,0,l,0);
		}
		cout<<endl;
	}
	return 0;
 }


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int t;
ll a[20],f[20][20];
ll dfs(ll pos,ll now,bool b){
	if(pos==0) return 1;
	if(!b && f[pos][now]!=-1) return f[pos][now];
	ll maxx=b ? a[pos] : 9;
	ll ans=0;
	for(int i=0;i<=maxx;i++){
		if(i==0) ans+=dfs(pos-1,now,b && a[pos]==i);
		else if(now!=3) ans+=dfs(pos-1,now+1,b && a[pos]==i);
	}
	if(!b) f[pos][now]=ans;
	return ans;
}
inline ll sol(int x){
	ll tot=0;
	while(x>0){
		a[++tot]=x%10;x/=10;
	}
	return dfs(tot,0,1);
}
int main()
{
	scanf("%d",&t);
	memset(f,-1,sizeof(f));
	while(t--){
		ll r,l;scanf("%lld%lld",&l,&r);
		printf("%lld\n",sol(r)-sol(l-1));
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int a[101],t[100][100],f[10];
int dfs(int k,bool ok,int sum)
{
//	cout<<last<<" "<<last2<<endl;
	if(sum>3)return 0;
	if(k==0)
	{
		if(sum<=3)
			return 1;
		else
			return 0;
	}
	int end=ok?a[k]:9;
	int s=0;
	if(!ok&&t[k][sum]!=-1)return t[k][sum];
	for(int i=0;i<=end;i++)
	{
		int ko=0;
		if(i!=0){
			ko=1;
		}
		s+=dfs(k-1,(ok)&&(i==end),sum+ko);
	}
	if(!ok)t[k][sum]=s;
	return s;
}
int chai(int n)
{
	//if(n==0)return 0;
	memset(a,0,sizeof(a));
	memset(t,-1,sizeof(t));
	memset(f,0,sizeof(f));
	int i=0;
	while(n!=0)
	{
		i++;
		a[i]=n%10;
		n/=10;
	}
	return dfs(i,1,0);
}
int main()
{
	int t;cin>>t;
	for(int i=1;i<=t;i++)
	{
		int n,m;
		cin>>n>>m;
		cout<<chai(m)-chai(n-1)<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL Q, l, r;
vector<long long> vc;
void init(int cnt, int pos, long long num) {
	if(pos == 18) {
		vc.push_back(num);
		return;
	}
	init(cnt, pos + 1, num * 10);
	if(cnt < 3)
		for(int i = 1 ; i <= 9 ; i ++)
			init(cnt + 1, pos + 1, num * 10 + i);
}
long long getnum(long long l, long long r) {
	return upper_bound(vc.begin(), vc.end(), r) - upper_bound(vc.begin(), vc.end(), l - 1);
}
int main() {
	init(0, 0, 0);
	vc.push_back(1000000000000000000);
	scanf("%lld", &Q);
	while(Q --) {
		scanf("%lld%lld", &l, &r);
		printf("%lld\n", getnum(l, r));
	}
	return 0;
}


/**
 * @Author: Mingyu Li
 * @Date:   2019-03-10T22:04:01+08:00
 * @Email:  class11limingyu@126.com
 * @Filename: CF1036C.cpp
 * @Last modified by:   Mingyu Li
 * @Last modified time: 2019-03-10T22:19:57+08:00
 */

#include <bits/stdc++.h>
#define tpname typename
#define Go(i , x , y) for(register int i = x; i <= y; i++)
#define God(i , y , x) for(register int i = y; i >= x; i--)
typedef long long LL;
typedef long double ld;
typedef unsigned long long ULL;
template < tpname T > void sc(T& t) {
  char c = getchar(); T x = 1; t = 0; while(!isdigit(c)) {if(c == '-') x = -1; c = getchar();}
  while(isdigit(c)) t = t * 10 + c - '0' , c = getchar();t *= x;
}
template < tpname T , tpname... Args > void sc(T& t , Args&... args) {sc(t); sc(args...);}
template < tpname T > T mul(T x , T y , T _) {
  x %= _,y %= _; return ((x * y - (T)(((ld)x * y + 0.5) / _) * _) % _ + _) % _;
}

// dp[x][y]:
// 还剩x位 已经填了j个非零数字
LL dp[25][25] , d[25];
LL f(LL x , LL y) {
  if(y > 3) return dp[x][y] = 0;
  if(dp[x][y] != -1) return dp[x][y];
  if(!x) return dp[x][y] = y <= 3 ? 1 : 0;
  LL ans = 0;
  Go(i , 0 , 9) {
    ans += f(x-1 , y + (i != 0));
  }
  return dp[x][y] = ans;
}

LL cal(LL x) {
  int m = 0;
  while(x) {
    d[m++] = x%10;
    x /= 10;
  }

  LL ans = 0;
  Go(i , 1 , m-1) {
    Go(j , 1 , 9) ans += f(i-1 , 1);
  }
  //std::cout << "nowans %% : " << ans << std::endl;
  LL cnt = 0;
  God(i , m-1 , 0) {
    Go(j , (i == m-1) ? 1 : 0 , d[i] - 1) {
      ans += f(i , cnt + (j != 0));
    }
    if(d[i]) cnt++;
    if(cnt > 3) break;
  }
  return ans;
}
int t;
LL l , r;
int main() {
  memset(dp , -1 , sizeof(dp));

  sc(t);
  while(t --> 0) {
    sc(l , r);
  //  std::cout << cal(1) << " " << cal(1000) << std::endl;
    std::cout << cal(r+1)  -cal(l) << std::endl;
  }
  return 0;
}


#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define reg register
typedef long long ll;
const int kmaxn=25;
ll dp[kmaxn][10][4];
int n;
void init()
{
    dp[1][0][0]=1;
    for(reg int i=1;i<10;++i)
        dp[1][i][1]=1;
    for(reg int i=2;i<=n;++i)
    {
        dp[i][0][0]=dp[i-1][0][0];
        for(reg int k=1;k<=3;++k)
        {
            for(reg int j=0;j<10;++j){
                dp[i][0][k]+=dp[i-1][j][k];
            }
            for(reg int j=1;j<10;++j)
            {
                for(reg int p=0;p<10;++p)
                {
                    dp[i][j][k]+=dp[i-1][p][k-1];
                }
            }
        }
    }
}
ll query(const vector<int>& vec)
{
    if(vec.size()==1&&vec[0]==0)return 0;
    ll ans=0;
    reg int cnt=0;
    for(reg int i=vec.size();i>0;--i)
    {
        for(reg int j=0;j<vec[i-1];++j)
        {
            for(reg int k=max(0,1-cnt);k<=3-cnt;++k)
            {
                ans+=dp[i][j][k];
            }
        }
        if(vec[i-1]) ++cnt;
        if(cnt>3) return ans+1;
    }
    return ans+1;
}
inline void trans(vector<int>& vec,const string& str)
{
    vec.clear();
    for(reg int i=str.size()-1;i>=0;--i)
    {
        vec.push_back(str[i]-'0');
    }
}
inline void add(vector<int>& vec)
{
    reg int t=1;
    for(reg int i=0,j=vec.size();i<j;++i)
    {
        vec[i]+=t;
        t=vec[i]/10;
        vec[i]%=10;
    }
    if(t)
        vec.push_back(t);
}
string l,r;
vector<int> lv,rv;
inline void solve()
{
    cin>>l>>r;
    trans(lv,l);
    trans(rv,r);
    add(rv);
    cout<<query(rv)-query(lv)<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);
    reg int t;
    cin>>t;
    n=19;
    init();
    while(t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

const int SIZE = 20 + 5;

int T, l, r, len;
int a[SIZE], f[SIZE][SIZE]; // f[pos][sum][limit];

inline int read()
{
    char ch = getchar();
    int f = 1, x = 0;
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); }
    return x * f;
}

inline int DFS(int pos, int sum, int limit)
{
    if (pos == 0) return 1;
    if (sum > 3) return 0;
    if (!limit && f[pos][sum] != -1) return f[pos][sum];
    int high = limit ? a[pos] : 9, ans = 0;
    for (int i = 0; i <= high; i++) {
        if (!i) ans += DFS(pos - 1, sum, i == high && limit);
        else ans += DFS(pos - 1, sum + 1, i == high && limit);
    }
    if (!limit) f[pos][sum] = ans;
    return ans;
}

inline int Div(int x)
{
    len = 0;
    while (x) a[++len] = x % 10, x /= 10;
    memset(f, -1, sizeof(f));
    return DFS(len, 0, 1);
}

signed main()
{
    T = read();
    while (T--) {
        l = read(), r = read();
        std::cout << Div(r) - Div(l - 1) << endl;
    }
    return 0;
}


#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[30];
ll dp[30][4];
ll dfs(int p,int h,bool lm){
	if(h<0) return 0;
	if(p<=0) return h>=0;
	if(dp[p][h]!=-1&&!lm)
	return dp[p][h];
	int end=lm? a[p]:9;
	ll ans=0;
	for(int i=0;i<=end;i++){
		ans+=dfs(p-1,h-(i?1:0),lm&&i==end);
	}
	if(!lm)
	dp[p][h]=ans;
	return ans;
}
ll solve(int p){
	int len=0;
	while(p){
		a[++len]=p%10;
		p/=10;
	}
	return dfs(len,3,1);
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		ll a,b;
		memset(dp,-1,sizeof(dp));
		scanf("%lld%lld",&a,&b);
		printf("%lld\n",solve(b)-solve(a-1));
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define Pos 20
#define Sum 20
#define ll unsigned long long
#define cti return 0
ll x,y,que,dp[Pos][Sum];
int bits[Pos];
ll dfs(ll pos,ll sum,bool limit)
{
	if(!pos)return 1;
	if(!limit&&dp[pos][sum]!=-1)return dp[pos][sum];
	int up=limit?bits[pos]:9;
	ll ans=0;
	for(int i=0;i<=up;++i)
	{
		if(sum>3)continue;
		if(i==0)ans+=dfs(pos-1,sum,limit&&i==up);
		else ans+=dfs(pos-1,sum+1,limit&&i==up);
	}
	if(!limit)dp[pos][sum]=ans;
	return ans;
}
ll solve(ll p)
{
	int top=0;
	while(p)
	{
		bits[++top]=p%10;
		p/=10;
	}
	return dfs(top,0,true);
}
int main()
{
	memset(dp,-1,sizeof dp);
	scanf("%d",&que);
	while(que--)
	{
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",solve(y)-solve(x-1));
	}
	cti;
}


#include <stdio.h>
#include <string.h>
int T,a[20];
long long l,r,dp[20][5];
long long dfs(int pos,int cnt,bool limit){
	if (!limit&&dp[pos][cnt]!=-1) return dp[pos][cnt];
	if (pos==0) return 1;
	long long ans=0;
	int up=limit?a[pos]:9;
	for (int i=0;i<=up;i++){
		if (i&&cnt==3) continue;
		ans+=dfs(pos-1,cnt+(i?1:0),limit&&i==up);
	}
	if (!limit) dp[pos][cnt]=ans;
	return ans;
}
long long solve(int n){
	int pos=0;
	while (n){
		a[++pos]=n%10;
		n/=10;
	}
	return dfs(pos,0,1);
}
int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%d",&T);
	while (T--){
		scanf("%lld%lld",&l,&r);
		printf("%lld\n",solve(r)-solve(l-1));
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
long long a[101],t[100][100],f[10];
long long dfs(int k,bool ok,int sum)
{
//	cout<<last<<" "<<last2<<endl;
	if(sum>3)return 0;
	if(k==0)
	{
		if(sum<=3)
			return 1;
		else
			return 0;
	}
	int end=ok?a[k]:9;
	long long s=0;
	if(!ok&&t[k][sum]!=-1)return t[k][sum];
	for(int i=0;i<=end;i++)
	{
		int ko=0;
		if(i!=0){
			ko=1;
		}
		s+=dfs(k-1,(ok)&&(i==end),sum+ko);
	}
	if(!ok)t[k][sum]=s;
	return s;
}
long long chai(long long n)
{
	//if(n==0)return 0;
	memset(a,0,sizeof(a));
	memset(t,-1,sizeof(t));
	memset(f,0,sizeof(f));
	int i=0;
	while(n!=0)
	{
		i++;
		a[i]=n%10;
		n/=10;
	}
	return dfs(i,1,0);
}
int main()
{
	int t;cin>>t;
	for(int i=1;i<=t;i++)
	{
		long long n,m;
		cin>>n>>m;
		cout<<chai(m)-chai(n-1)<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#define il inline
#define vd void
#define ll long long
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define drp(i,x,y) for(register int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il ll rd(); il vd pc(char c); il vd rt(ll x); il vd flush();
template<class T> il T Max(T a,T b){return a>b?a:b;}
template<class T> il T Min(T a,T b){return a<b?a:b;}
int T;
ll l,r,cnt,p[22],pp[22],dp[22][5][3];
il ll Get(ll x){ll t=x; cnt=0;
	if(x==0) return 1;
	while(t) pp[++cnt]=t%10,t/=10;
	rep(i,1,cnt) p[i]=pp[cnt-i+1];
	memset(dp,0,sizeof(dp));
	dp[0][0][1]=1;
	rep(i,1,cnt){
		rep(k,0,1){int limit=k?p[i]:9;
			rep(j,1,limit) rep(s,1,3) dp[i][s][k&&j==p[i]]+=dp[i-1][s-1][k];
			rep(s,0,3) dp[i][s][k&&p[i]==0]+=dp[i-1][s][k];
		}
	}
	return dp[cnt][0][0]+dp[cnt][0][1]+dp[cnt][1][0]+dp[cnt][1][1]+dp[cnt][2][0]+dp[cnt][2][1]+dp[cnt][3][0]+dp[cnt][3][1];
}
int main(){
	T=rd();
	while(T--) l=rd(),r=rd(),rt(Get(r)-Get(l-1)),pc('\n');
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il ll rd(){char c; ll f=1;
	while(!isdigit(c=gc())&&c!='-');
	c=='-'?f=-1,c=gc():0; ll x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return x*f;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(ll x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}


#include<cstdio>
#include<cstring>
#include<string>

using namespace std;

long long c[25][25];
long long pw[5];

inline long long C(int n, int k) {
	return k < 0 || k > n ? 0 : c[n][k];
}

inline void pre() {
	for (int i = 0; i <= 20; ++i) {
		c[i][0] = c[i][i] = 1;
		for (int j = 1; j < i; ++j) {
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
		}
	}

	pw[0] = 1;
	pw[1] = 9;
	pw[2] = 81;
	pw[3] = 729;
}

inline long long qaq(int n, int l) {
	long long res = 0;
	for (int i = 0; i <= l; ++i) {
		res += C(n, i) * pw[i];
	}
	return res;
}

inline long long calc(long long x) {
	string s = to_string(x);

	long long res = 0;
	int cnt = 3;

	for (int i = 0, len = s.size(); i < len; ++i) {
		if (s[i] == '0') continue;
		else {
			res += qaq(len - i - 1, cnt);
			--cnt;
			if (cnt < 0) break ;
			res += qaq(len - i - 1, cnt) * (s[i] - '1');
		}
	}

	return res;
}

long long t, l, r;

int main() {
	pre();

	scanf("%lld", &t);
	while (t--) {
		scanf("%lld%lld", &l, &r);

		long long ans = calc(r + 1) - calc(l);

		printf("%lld\n", ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const long long Max_N = 1e18;
vector <LL> vt;
void dfs(LL num, int cnt, int length)
{
    if (length > 18) return;
    vt.push_back(num);
    for (int i = 0;i <= 9;i ++)
    {
        int k = cnt;
        if (i != 0) k = k + 1;
        if (k <= 3) dfs(num * 10 + i, k, length + 1);
    }
}
int main()
{
    dfs(1, 1, 1);
    sort(vt.begin(), vt.end());
    int T; scanf("%d", &T);
    while (T--)
    {
        LL L, R; scanf("%lld%lld", &L, &R);
        LL l =lower_bound(vt.begin(), vt.end(), L) - vt.begin();
        LL r =lower_bound(vt.begin(), vt.end(), R) - vt.begin();
        printf("%lld\n", r - l);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const long long Max_N = 1e18;
vector <LL> vt;
void dfs(LL num, int cnt, int length)
{
    if (length > 18) return;
    vt.push_back(num);
    for (int i = 0;i <= 9;i ++)
    {
        int k = cnt;
        if (i != 0) k = k + 1;
        if (k <= 3) dfs(num * 10 + i, k, length + 1);
    }
}
int main()
{
    for (int i = 1;i <=9 ; i++) dfs(i, 1, 1);
    vt.push_back(Max_N);
    sort(vt.begin(), vt.end());
    //for (int i = 123456;i <= 654321; i++)
    //    cout << vt[i] << endl;
    int T; scanf("%d", &T);
    while (T--)
    {
        LL L, R; scanf("%lld%lld", &L, &R);
        LL cnt = upper_bound(vt.begin(), vt.end(), R) - lower_bound(vt.begin(), vt.end(), L);
        printf("%lld\n", cnt);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const long long Max_N = 1e18;
vector <LL> vt;
void dfs(LL num, int cnt, int length)
{
    if (length > 18) return;
    vt.push_back(num);
    for (int i = 0;i <= 9;i ++)
    {
        int k = cnt;
        if (i != 0) k = k + 1;
        if (k <= 3) dfs(num * 10 + i, k, length + 1);
    }
}
int main()
{
    for (int i = 1;i <=9 ; i++) dfs(i, 1, 1);
    sort(vt.begin(), vt.end());
    //for (int i = 123456;i <= 654321; i++)
    //    cout << vt[i] << endl;
    int T; scanf("%d", &T);
    while (T--)
    {
        LL L, R; scanf("%lld%lld", &L, &R);
        LL cnt = lower_bound(vt.begin(), vt.end(), R) - lower_bound(vt.begin(), vt.end(), L);
        printf("%lld\n", cnt + 1);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const long long Max_N = 1e18;
vector <LL> vt;
void dfs(LL num, int cnt, int length)
{
    if (length > 18) return;
    vt.push_back(num);
    for (int i = 0;i <= 9;i ++)
    {
        int k = cnt;
        if (i != 0) k = k + 1;
        if (k <= 3) dfs(num * 10 + i, k, length + 1);
    }
}
int main()
{
    for (int i = 1;i <=9 ; i++) dfs(i, 1, 1);
    sort(vt.begin(), vt.end());
    //for (int i = 123456;i <= 654321; i++)
    //    cout << vt[i] << endl;
    int T; scanf("%d", &T);
    while (T--)
    {
        LL L, R; scanf("%lld%lld", &L, &R);
        LL cnt = upper_bound(vt.begin(), vt.end(), R) - lower_bound(vt.begin(), vt.end(), L);
        printf("%lld\n", cnt);
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <utility>

#define endl '\n'
#define _ ios::sync_with_stdio(false), cin.tie(NULL)
#define iread freopen("i1.txt", "r", stdin)

using namespace std;

// clock_t tstart;void sc(){tstart=clock();} void pc(){printf("time=%.3f\n", (clock()-tstart)/(CLOCKS_PER_SEC*1.0));}

int t, keep=0;

long long l, r;
string sl, sr;

long long dp[20004][20][4][2];

long long calc(int pos, int n, string x, int nonzero, bool fl) {
	if(pos==n) return 1;
	if(dp[keep][pos][nonzero][fl]!=-1) return dp[keep][pos][nonzero][fl];
	long long ans=0;
	if(nonzero<3) {
		for(long long i=1; i<=9; ++i) {
			if(fl || (!fl && i<=x[pos]-'0'))
				ans+=calc(pos+1, n, x, nonzero+1, fl|(i<x[pos]-'0'));
		}
	}
	ans+=calc(pos+1, n, x, nonzero, fl|(0<x[pos]-'0'));
	return (dp[keep][pos][nonzero][fl]=ans);
}

int main () {
    //iread;
    _;
    cin>>t;
    memset(dp, (-1), sizeof dp);
    long long aa;
    while(t--) {
    	cin>>l>>r;
    	sl=sr="";
    	l--;
    	if(l==0) sl+='0';
    	while(l>0) {
    		sl+=(l%10)+'0';
    		l/=10;
    	}
    	if(r==0) sr+='0';
    	while(r>0) {
    		sr+=(r%10)+'0';
    		r/=10;
    	}
    	while((int)sl.size()<(int)sr.size()) sl+='0';
    	reverse(sl.begin(), sl.end());
    	reverse(sr.begin(), sr.end());
    	//cout<<sl<<' '<<sr<<endl;
    	aa=calc(0, (int)sr.size(), sr, 0, 0);
    	keep++;
    	cout<<aa-calc(0, (int)sl.size(), sl, 0, 0)<<endl;
    	keep++;
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <utility>

#define endl '\n'
#define _ ios::sync_with_stdio(false), cin.tie(NULL)
#define iread freopen("i1.txt", "r", stdin)

using namespace std;

// clock_t tstart;void sc(){tstart=clock();} void pc(){printf("time=%.3f\n", (clock()-tstart)/(CLOCKS_PER_SEC*1.0));}

int t;

long long l, r;
string sl, sr;

long long dp[20][4][2];

long long calc(int pos, int n, string x, int nonzero, bool fl) {
	if(pos==n) return 1;
	if(dp[pos][nonzero][fl]!=-1) return dp[pos][nonzero][fl];
	long long ans=0;
	if(nonzero<3) {
		for(long long i=1; i<=9; ++i) {
			if(fl || (!fl && i<=x[pos]-'0'))
				ans+=calc(pos+1, n, x, nonzero+1, fl|(i<x[pos]-'0'));
		}
	}
	ans+=calc(pos+1, n, x, nonzero, fl|(0<x[pos]-'0'));
	return (dp[pos][nonzero][fl]=ans);
}

int main () {
    //iread;
    _;
    cin>>t;
    long long aa;
    while(t--) {
    	cin>>l>>r;
    	sl=sr="";
    	memset(dp, (-1), sizeof dp);
    	l--;
    	if(l==0) sl+='0';
    	while(l>0) {
    		sl+=(l%10)+'0';
    		l/=10;
    	}
    	if(r==0) sr+='0';
    	while(r>0) {
    		sr+=(r%10)+'0';
    		r/=10;
    	}
    	while((int)sl.size()<(int)sr.size()) sl+='0';
    	reverse(sl.begin(), sl.end());
    	reverse(sr.begin(), sr.end());
    	//cout<<sl<<' '<<sr<<endl;
    	aa=calc(0, (int)sr.size(), sr, 0, 0);
    	memset(dp, (-1), sizeof dp);
    	cout<<aa-calc(0, (int)sl.size(), sl, 0, 0)<<endl;
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <utility>

#define endl '\n'
#define _ ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define iread freopen("i1.txt", "r", stdin)

using namespace std;

// clock_t tstart;void sc(){tstart=clock();} void pc(){printf("time=%.3f\n", (clock()-tstart)/(CLOCKS_PER_SEC*1.0));}

int t, keep=0;

long long l, r;
string sl, sr;

long long dp[20004][20][4][2];

long long calc(int pos, int n, string x, int nonzero, bool fl) {
	if(pos==n) return 1;
	if(dp[keep][pos][nonzero][fl]!=-1) return dp[keep][pos][nonzero][fl];
	long long ans=0;
	if(nonzero<3) {
		for(long long i=1; i<=9; ++i) {
			if(fl || (!fl && i<=x[pos]-'0'))
				ans+=calc(pos+1, n, x, nonzero+1, fl|(i<x[pos]-'0'));
		}
	}
	ans+=calc(pos+1, n, x, nonzero, fl|(0<x[pos]-'0'));
	return (dp[keep][pos][nonzero][fl]=ans);
}

int main () {
    //iread;
    _;
    cin>>t;
    memset(dp, (-1), sizeof dp);
    long long aa;
    while(t--) {
    	cin>>l>>r;
    	sl=sr="";
    	l--;
    	if(l==0) sl+='0';
    	while(l>0) {
    		sl+=(l%10)+'0';
    		l/=10;
    	}
    	if(r==0) sr+='0';
    	while(r>0) {
    		sr+=(r%10)+'0';
    		r/=10;
    	}
    	while((int)sl.size()<(int)sr.size()) sl+='0';
    	reverse(sl.begin(), sl.end());
    	reverse(sr.begin(), sr.end());
    	//cout<<sl<<' '<<sr<<endl;
    	aa=calc(0, (int)sr.size(), sr, 0, 0);
    	keep++;
    	cout<<aa-calc(0, (int)sl.size(), sl, 0, 0)<<endl;
    	keep++;
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <utility>

#define endl '\n'
#define _ ios::sync_with_stdio(false), cin.tie(NULL)
#define iread freopen("i1.txt", "r", stdin)

using namespace std;

// clock_t tstart;void sc(){tstart=clock();} void pc(){printf("time=%.3f\n", (clock()-tstart)/(CLOCKS_PER_SEC*1.0));}

int t, keep=0;

long long l, r;
string sl, sr;

long long dp[20004][20][4][2];

long long calc(int pos, int n, string x, int nonzero, bool fl) {
	if(pos==n) return 1;
	if(dp[keep][pos][nonzero][fl]!=-1) return dp[keep][pos][nonzero][fl];
	long long ans=0;
	if(nonzero<3) {
		if(fl) {
			ans+=9*calc(pos+1, n, x, nonzero+1, fl);
		}
		else {
			for(long long i=1; i<=9; ++i) {
				if(i<=x[pos]-'0')
					ans+=calc(pos+1, n, x, nonzero+1, fl|(i<x[pos]-'0'));
			}
		}
	}
	ans+=calc(pos+1, n, x, nonzero, fl|(0<x[pos]-'0'));
	return (dp[keep][pos][nonzero][fl]=ans);
}

int main () {
    //iread;
    _;
    cin>>t;
    memset(dp, (-1), sizeof dp);
    long long aa;
    while(t--) {
    	cin>>l>>r;
    	sl=sr="";
    	l--;
    	if(l==0) sl+='0';
    	while(l>0) {
    		sl+=(l%10)+'0';
    		l/=10;
    	}
    	if(r==0) sr+='0';
    	while(r>0) {
    		sr+=(r%10)+'0';
    		r/=10;
    	}
    	while((int)sl.size()<(int)sr.size()) sl+='0';
    	reverse(sl.begin(), sl.end());
    	reverse(sr.begin(), sr.end());
    	//cout<<sl<<' '<<sr<<endl;
    	aa=calc(0, (int)sr.size(), sr, 0, 0);
    	keep++;
    	cout<<aa-calc(0, (int)sl.size(), sl, 0, 0)<<endl;
    	keep++;
    }
    return 0;
}