#include<iostream>
#include<vector>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
ll btd(ll n) // Desimaalit binääriksi
{
ll num = n;
ll dec_value = 0;
ll base = 1;
ll temp = num;
while (temp) {
ll last_digit = temp % 10;
temp = temp / 10;
dec_value += last_digit * base;
base = base * 2;
}
return dec_value;
}
ll calc(ll input, bool roundUp) {
string inputStr = to_string(input);
ll zeroes = inputStr.size() - 1;
ll rounded = 0;
for (ll i = 0; i <= inputStr.size() - 1; i++) {
bool roundedUp = false;
ll cur = 0;
if (!roundUp) {
char curChar = inputStr[i];
cur = (ll)curChar - 48;
if (cur > 1) { // eg. 200 -> 111
for (ll b = 0; b < inputStr.size()-i+1; b++) {
inputStr[inputStr.size()-b] = 1+48;
cur = 1;
}
}
rounded += cur * pow(10, inputStr.size() - 1 - i);
}
else {
char curChar = inputStr[inputStr.size()-i-1];
cur = (ll)curChar - 48;
if (cur > 1) {
ll temp = input;
temp /= pow(10, i+1);
temp *= pow(10, i+1);
temp = temp + pow(10, i+1);
inputStr = to_string(temp);
input = temp;
roundedUp = true;
}
}
}
if (roundUp) {
rounded = input;
}
return rounded;
}
ll main()
{
ll rows = 0;
vector< vector<ll > > inputs;
cin >> rows;
/*for (ll i = 0; i < rows+1; i++) {
ll input1 = i;
ll input2 = rows;
vector<ll> input = { input1, input2 };
inputs.push_back(input);
}*/
for (ll i = 0; i < rows; i++) {
ll input1=0;
ll input2=0;
cin >> input1 >> input2;
vector<ll > input = { input1, input2 };
inputs.push_back(input);
}
for (ll i = 0; i < rows; i++) {
ll result = 0;
ll roundedA = calc(inputs[i][0], true);
ll roundedB = calc(inputs[i][1], false);
ll a = btd(roundedA);
ll b = btd(roundedB);
result = b - a + 1;
if (a>b) {
result = 0;
}
cout << result << endl;
//cout << result << " A is " << inputs[i][0] << " B is " << inputs[i][1] << endl;
}
}