#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <climits>
using namespace std;
typedef long long LL;

#define MODNUM 1000000007

LL factorial(LL n) {
	if (n == 0) return 1LL;
	return n + factorial(n - 1);
}

LL result(LL a, LL b) {
	LL p = 1;
	while (p - 1 < a)
		p <<= 1;
	LL prevnum = a;
	LL ans = 0LL;
	int exitnext = false;
	while (!exitnext) {
		if (p - 1 >= b)
			exitnext = true;
		if (min(p - 1, b) < prevnum)
			break;
		LL L = min(p - 1, b) - prevnum + 1;
		L = L * (L + 1) / 2;
		ans += L;
		ans %= MODNUM;
		prevnum = p;
		p <<= 1;
	}
	return ans;
}

int main() {
	int Q;
	scanf("%d", &Q);
	while (Q--) {
		LL a, b;
		scanf("%lld%lld", &a, &b);
		printf("%lld\n", result(a, b));
	}
	return 0;
}