#include using namespace std; long long amnt[10000]; int main() { #define int long long const int MOD = 1000000007; int T; cin >> T; while (T) { int L, R; cin >> L >> R; int l = 0; int LL = L; while (LL) { LL /= 2; l ++; } int r = 0; int RR = R; while (RR) { RR /= 2; r ++; } int nxt = (1LL << (l)); amnt[0] = nxt - L; if (r == l) { amnt[0] = R - L + 1; cout << amnt[0] * (amnt[0] + 1) / 2 << "\n"; T--; continue; } int last = nxt; int cur = 1; while (nxt * 2 < R) { nxt *= 2; amnt[cur] = nxt - last; cur++; } amnt[cur] = R - nxt + 1; cur++; int ans = 0; for (int i = 0; i < cur; i++) { ans = (ans + amnt[i] * (amnt[i] + 1LL) / 2LL) % MOD; } cout << (ans + MOD) % MOD << "\n"; T--; } return 0; }