#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using pii = pair<int, int>;
#define dbg(x) cerr<<#x": "<<(x)<<'\n'
#define dbg_v(x, n) cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<'\n'
#define all(v) v.begin(), v.end()
#define NMAX 

int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);

	int q, x, y, a, b, n;
	ll sum;

	for(cin >> q; q; --q)
	{
		cin >> x >> y;

		for(sum = 0, n = 0; n <= 30; ++n)
		{
			a = max(x, 1 << n);
			b = min(y, (1 << (n + 1)) - 1);
			if(a > b) continue;

			//dbg(a); dbg(b);

			sum += 1LL * (b - a + 1) * (b + 1);
			sum -= 1LL * (b + a) * (b - a + 1) / 2;
		}

		cout << sum % 1000000007 << '\n';
	}

	return 0;
}