#include <iostream>
#include <cmath>
#include <vector>
#define EPS 0.000000001
using namespace std;


int get_x(int p) { 
	__int64 px = 1, x = 0;
	while (px < p) {
		px *= 2;
		x++;
	}
	if (px == p) 
		return x;
	return x - 1; 
}
int pow(int x, int y) {
	return (int)pow((double)x, y);
}
int main()
{
	freopen("FLOAT.IN", "r", stdin);
	int t;
	cin >> t;
	while (t--)
	{
		__int64 p, q;
		cin >> p >> q;
		if (q < pow(2.0, 24)) {
			cout << q - p + 1 << endl;
			continue;
		}
		

		int px = get_x(p);
		int qx = get_x(q);
		int p_full_bit = p & (pow(2, px) - 1);
		unsigned int p_mask = (pow(2, 32) - 1 ) & ((pow(2, px - 23) -1) );
		int q_full_bit = q & (pow(2, qx) - 1);
		unsigned int q_mask = (pow(2, 32) - 1 ) & ((pow(2, qx - 23) -1));
		int first_23_q = ((q_full_bit & ~q_mask) >> (qx - 23)),
			first_23_p = ((p_full_bit & ~p_mask) >> (px - 23));
		int last_q = q_full_bit & (q_mask),
			last_p = p_full_bit & (p_mask);
		if (px == qx) {
			if (last_p == 0)
				cout <<first_23_q -first_23_p  + 1 << endl;
			else
				cout <<first_23_q -first_23_p  << endl;
			continue;
		}
				
		if (qx > px) {
			if (px >= 24) {
				int p23_first_p = pow(2, 23) - first_23_p;
				if (last_p != 0)
					p23_first_p--;
				int first_q = first_23_q + 1;
				cout << p23_first_p + first_q + (qx - px - 1) * pow(2, 23) << endl;
			} else {
				int first_q = first_23_q + 1;
				cout << first_q + pow(2, 24) - p + (qx - 23 - 1) * pow(2, 23) << endl;
			}
		}


	}
	return 0;
}