#include<iostream>
unsigned long long powsOf10[20]
{
1,
10,
100,
1'000,
10'000,
100'000,
1'000'000,
10'000'000,
100'000'000,
1'000'000'000,
10'000'000'000,
100'000'000'000,
1'000'000'000'000,
10'000'000'000'000,
100'000'000'000'000,
1'000'000'000'000'000,
10'000'000'000'000'000,
100'000'000'000'000'000,
1'000'000'000'000'000'000,
10'000'000'000'000'000'000
};
unsigned long long ones[19]
{
1,
11,
111,
1'111,
11'111,
111'111,
1'111'111,
11'111'111,
111'111'111,
1'111'111'111,
11'111'111'111,
111'111'111'111,
1'111'111'111'111,
11'111'111'111'111,
111'111'111'111'111,
1'111'111'111'111'111,
11'111'111'111'111'111,
111'111'111'111'111'111,
1'111'111'111'111'111'111
};
int main()
{
int n;
scanf("%d", &n);;
long long a;
long long b;
long long temp;
int toA = 0;
int toB = 0;
int between;
int omA = 0;
int omB = 0;
bool aValid = false;
bool bValid = false;
for (int i = 0; i < n; i++)
{
scanf("%lld", &a);
scanf("%lld", &b);
for (int i = 1; i < 20; i++)
{
if(a%powsOf10[i] == a)
{
omA = i - 1;
break;
}
}
for (int i = 1; i < 20; i++)
{
if (b % powsOf10[i] == b)
{
omB = i - 1;
break;
}
}
toA = 2 << omA;
for (int i = 0; i < (1 << omA); i++)
{
temp = 0;
for (int j = 0; j < omA; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (a < (powsOf10[omA] + temp))
toA--;
}
toB = 2 << omB;
for (int i = 0; i < (1 << omB); i++)
{
temp = 0;
for (int j = 0; j < omB; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (b < (powsOf10[omB] + temp))
toB--;
}
aValid = true;
while (a > 0)
{
int remainder = a % 10;
if (remainder > 1)
{
aValid = false;
break;
}
a /= 10;
}
bValid = true;
while (a > 0)
{
int remainder = a % 10;
if (remainder > 1)
{
bValid = false;
break;
}
a /= 10;
}
between = toB - toA + aValid;
printf("%d\n", between);
}
return 0;
}