#include #define pb push_back #define f first #define s second #define pii pair #define mp make_pair using namespace std; const string file_name = "C", input_file = file_name + ".in", output_file = file_name + ".out"; ifstream fin(input_file); ofstream fout(output_file); const int MOD = 1e9 + 7; long long compute(long long lower_bound, long long upper_bound) { long long temp = max(upper_bound - lower_bound + 1, 0LL); if (temp & 1) { temp = (temp + 1) / 2 * temp; } else { temp = temp / 2 * (temp + 1); } return temp % MOD; } long long solve(long long x, long long y) { long long sol = 0; for (int i = 0; i < 31; i++) { long long lower_bound = max(x, (1LL << i)), upper_bound = min(y, (1LL << (i + 1)) - 1); sol = (sol + compute(lower_bound, upper_bound)) % MOD; } return sol; } int main() { cin.sync_with_stdio(false); int q; cin >> q; for (long long a, b; q; q--) { cin >> a >> b; cout << solve(a, b) << '\n'; } return 0; }