#include using namespace std; const int Mod = 1e9 + 7; long long gauss(int i) { if (i % 2 == 0) return 1LL * (i / 2) * (i + 1); return 1LL * ((i + 1) / 2) * i; } long long gauss(int i, int j) { return gauss(j) - gauss(i - 1); } long long Find(int x) { for (long long i = 0; i <= 33; ++i) if ((1LL << i) > x)return 1LL << i; return -1; } int main() { #ifndef ONLINE_JUDGE freopen("data.in", "r", stdin); freopen("data.out", "w", stdout); #endif // ONLINE_JUDGE ios::sync_with_stdio(0); int n; cin >> n; for (; n; --n) { int64_t x, y; cin >> x >> y; long long cnt = 0; for (int64_t i = x; i <= y;) { long long Urm = Find(i); Urm = min(Urm, y + 1); cnt -= gauss(i, Urm); cnt += (Urm - i + 1) * Urm; cnt %= Mod; i = Urm; } cout << cnt << '\n'; } }