#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef double lf; typedef long double Lf; typedef pair pii; typedef pair pll; #define TRACE(x) cerr << #x << " " << x << endl #define FOR(i, a, b) for (int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) #define all(x) (x).begin(), (x).end() #define _ << " " << #define fi first #define sec second #define mp make_pair void solve() { int a, b; scanf("%d %d",&a,&b); int pot = 1; ll sol = 0; while (pot < a) pot *= 2; if (pot > b) { printf("%lld\n",(ll)(b - a + 1) * (b - a + 2) / 2); return; } int l = pot - a; sol += (ll)l * (l + 1) / 2; int last = pot; if (pot * 2 > b) { sol += (ll)(b - pot + 1) * (b - pot + 2) / 2; printf("%lld\n",sol); return; } pot *= 2; while (pot <= b) { l = pot - last; sol += (ll)l * (l + 1) / 2; last = pot; pot *= 2; } sol += (ll)(b - last) * (b - last + 1) / 2; printf("%lld\n",sol); } int main() { int t; scanf("%d",&t); REP(i, t) solve(); return 0; }