#include<iostream>
int main()
{
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 n;
std::cin >> n;
long long a;
long long b;
long long temp1;
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++)
{
std::cin >> a;
std::cin >> b;
for (int i = 0; i < 20; i++)
{
if(a%powsOf10[i] == a)
{
omA = i - 1;
break;
}
}
for (int i = 0; i < 20; i++)
{
if (b % powsOf10[i] == b)
{
omB = i - 1;
break;
}
}
if (a == 0)
toA = 1;
else
{
toA = 2 << omA;
if (omA == 0)
{
for (int i = 0; i < 2; i++)
{
temp = 0;
for (int j = 0; j < omA; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (a < (powsOf10[omA] + temp))
toA--;
}
}
else
{
for (int i = 0; i < (2 << (omA - 1)); i++)
{
temp = 0;
for (int j = 0; j < omA; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (a < (powsOf10[omA] + temp))
toA--;
}
}
}
if (b == 0)
toB = 1;
else
{
toB = 2 << omB;
if (omB == 0)
{
for (int i = 0; i < 2; i++)
{
temp = 0;
for (int j = 0; j < omB; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (b < (powsOf10[omB] + temp))
toB--;
}
}
else
{
for (int i = 0; i < (2 << (omB-1)); i++)
{
temp = 0;
for (int j = 0; j < omB; j++)
{
temp += powsOf10[j] * (i >> j & 1);
}
if (b < (powsOf10[omB] + temp))
toB--;
}
}
}
aValid = true;
int tempA = a;
while (tempA > 0)
{
int remainder = tempA % 10;
if (remainder != 0 && remainder != 1)
{
aValid = false;
break;
}
tempA /= 10;
}
bValid = true;
int tempB = b;
while (tempB > 0)
{
int remainder = tempB % 10;
if (remainder != 0 && remainder != 1)
{
bValid = false;
break;
}
tempB /= 10;
}
if (a == b)
{
between = 0 + bValid;
}
else if (toA == toB)
{
between = toB - toA + aValid;
}
else
{
between = toB - toA + aValid;
}
std::cout << between << '\n';
}
return 0;
}