cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> PII;
#define pb emplace_back
//#define int ll
#define all(a) a.begin(),a.end()
#define x first
#define y second
#define ps push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
void solve();
const int N = 2e6 + 10;
signed main() {
IOS;
solve();
return 0;
}
ll sb(ll a)
{
ll ans = 0;
ll a1 = a-1,a2 = a;
for(int i = 0; i <= 30; ++ i)
{
if((a1&(1<<i)) != (a2&(1<<i)))
ans ++;
}
return ans;
}
void solve() {
vector<ll> a(N);
for(int i = 1; i < N; ++ i)
{
a[i] = sb(i);
a[i] += a[i-1];
}
ll t;
cin >> t;
while(t--)
{
ll x,y;
cin >> x >> y;
y = x + y;
cout << a[y] - a[x] << endl;
}
}