#include #include #define MOD 1000000007LL using namespace std; long long calc (long long val) { return 1LL * val * (val + 1) / 2LL; } void modd (long long &rez) { if (rez >= MOD) rez %= MOD; } int main () { //freopen ("file.in", "r", stdin); int q; scanf ("%d", &q); for (; q; --q) { long long rez = 0LL; int x, y; scanf ("%d %d", &x, &y); long long p1 = 1LL, p2 = 2LL; for (; p1 <= x; p1 *= 2LL, p2 *= 2LL); p1 /= 2LL; p2 /= 2LL; if (p2 > y) modd (rez = calc (y - x + 1)); else { modd (rez = calc (p2 - x)); p1 *= 2LL, p2 *= 2LL; for (; p2 <= y; p1 *= 2LL, p2 *= 2LL) modd (rez += calc (p2 - p1)); modd (rez += calc (y - p1 + 1)); } printf ("%lld\n", rez); } return 0; }