#include<iostream>
unsigned long long powsOf10[19]
{
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
};
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;
for (int i = 0; i < n; i++)
{
scanf("%lld", &a);
scanf("%lld", &b);
for (int i = 18; i >= 0; i--)
{
omA = i;
if(a%powsOf10[i] != a)
break;
}
for (int i = 18; i >= 0; i--)
{
omB = i;
if (b % powsOf10[i] != b)
break;
}
toA = 2 << omA;
for (int i = 0; i < (1 << omA); i++)
{
temp = powsOf10[omA];
for (int j = 0; j < omA; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (a < temp)
toA--;
}
toB = 2 << omB;
for (int i = 0; i < (1 << omB); i++)
{
temp = powsOf10[omB];
for (int j = 0; j < omB; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (b < temp)
toB--;
}
aValid = true;
while (a > 0)
{
int remainder = a % 10;
if (remainder > 1)
{
aValid = false;
break;
}
a /= 10;
}
between = toB - toA + aValid;
printf("%d\n", between);
}
return 0;
}