/*
	Task solves the following problem:
	- How many integer numbers from this interval can
	be precisely represented in floating point values (to allow back conversion).
*/


#include <iostream>
#include <set>
#include <fstream>
#include <vector>
#include <cassert>
#include <ctime>
#include <string>

using namespace std;

const int mantissa_len = 23;

// a bruteforce solution. Times out on large intervals.
int bf(int a, int b)
{
	int res = 0;
	for (;a <= b && a > 0;a++)
	{
		float f = a;
		if ((int)f == a)
			res++;
	}
	return res;
}

string to_bin(int a)
{
	char buf[34];
	itoa(a, buf, 2);
	return string(buf);
}

// calculates number of numbers of length n between low and hi,
// considering mantissa length.
int cnt(int low, int hi, int n)
{
	if (n - 1 <= mantissa_len)	// fits perfectly in mantissa
		return hi - low + 1;

	// other case - mantissa if varying.

	int zeros_cnt_end = n - 1 - mantissa_len;
	int res = 0;
	for (int mask = 0;mask < (1 << mantissa_len);mask++)
	{
		int num = (mask << zeros_cnt_end) | (1 << (n - 1));
		if (low <= num && num <= hi)
			res++;
	}
	return res;
}

int solve(int a, int b)
{
	assert(a <= b);

	int ll = to_bin(a).length();
	int ul = to_bin(b).length();

	// simple case. Just between two numbers of same length.
	if (ll == ul)
		return cnt(a, b, ll);

	int res = cnt(a, (1 << ll) - 1, ll)
			+ cnt(1 << (ul - 1), b, ul);

	for (int n = ll + 1;n <= ul - 1;n++)
		res += cnt(1 << (n - 1), (1 << n) - 1, n);

	return res;
}

void generate_tests()
{
	freopen("float.out.gen", "w", stdout);

	srand(clock());
	int start = (1 << 25) - 2;
	int end = 2147483647;


	int tc = 20;
	cout <<tc * 2<< endl;
	for (int i = 0;i < tc;i++)
	{

		int a, b;
		a = (rand() % (end - start)) + start + 1;
		b = (rand() % (end - a)) + a;

		cout <<a <<" " <<b <<endl;
	}

	for (int i = 0;i < tc;i++)
	{
		int a = (rand() % (end - start)) + start + 1;
		cout <<a <<" " <<a << endl;
	}
}

void main()
{
	//generate_tests();
	//return;

	freopen("float.in", "r", stdin);

	int tc;
	cin >>tc;

	for (int cc = 0;cc < tc;cc++)
	{
		int a, b;
		cin >>a >>b;
		assert(a <= b);
		assert(1 <= a && a <= 2147483647);
		assert(1 <= b && b <= 2147483647);

		int cnt = solve(a, b);			
		cout << cnt << endl;
	}
}
