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