//412_4
#include <iostream>
#include <algorithm>
#include <stdio.h>

using namespace std;

void answer()
{
    long long p, q, a, b, pl, l, an, ym, r, s;
    int n;

    scanf("%lld %lld", &p, &q);

    if(p>q)
    {
        printf("0\n");
        return;
    }
    an = 0;

    r = 1<<24;
    if( q<r )
    {
        printf("%lld\n", q-p+1);
        return;
    }

    if( p<r )
        an += r-p;

    for(n=24; n<=33; ++n)
    {
        a = 1 << n;
        b = (1 << (n+1)) - 1;
        pl = 1<<(n-23);


        if(p>b) continue;
        if(q<a) break;

       // printf("n=%d\na=%lld\nb=%lld\npl=%lld\np=%lld\nq=%lld\n\n\n", n, a, b, pl, p, q);
       // printf("kol=%lld\n", (b-a)/pl+1 );

        for(s=a; s<=b; s+=pl)
            if( (s>=p) && (s<=q) )
                ++an;
    }
    printf("%lld\n",an);
}
int main(){
    freopen("FLOAT.IN","r", stdin);
    //freopen("input.txt", "r", stdin);

    int t;
    scanf("%d", &t);
    while(t--)
        answer();
    return 0;
}


