//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <bitset>

using namespace std;

//ifstream cin("tema.in");
//ofstream cout("tema.out");

const int MAXLOG = 30;

long long Sum(int x) {
    return 1LL * x * (x + 1) / 2;
}

int main() {
    int tests;
    cin >> tests;
    for (int test = 1; test <= tests; test++) {
        int x, y;
        cin >> x >> y;
        long long answer = 0;
        for (int bit = 0; bit <= MAXLOG; bit++)
            if ((x < (1 << (bit + 1))) && (y >= (1 << bit)))
                answer += Sum(min(y, (1 << (bit + 1)) - 1) - max(x, 1 << bit) + 1);
        cout << answer << "\n";
    }
    return 0;
}