#include #include #include #include #include #include #include #include #include #include #define LL long long #define LD double #define inf 10000000000000000ll #define mo 100000007 using namespace std; long long mi[70]; int main() { mi[0]=1;for (int i=1;i<=61;i++) mi[i]=mi[i-1]*2; int t;scanf("%d",&t); while (t--) { long long l1,r1,l2,r2,ans=0; scanf("%I64d%I64d%I64d%I64d",&l1,&r1,&l2,&r2); for (int i=61;i>=0;i--) { if ((l1<=mi[i])&&(mi[i]<=r1)&&(l2<=mi[i]-1)&&(mi[i]-1<=r2)) { ans+=mi[i+1]-1; break; } if ((l2<=mi[i])&&(mi[i]<=r2)&&(l1<=mi[i]-1)&&(mi[i]-1<=r1)) { ans+=mi[i+1]-1; break; } if ((!(r1&mi[i]))&&(!(r2&mi[i]))) continue; if ((l1&mi[i])&&(l2&mi[i])) { l1-=mi[i];l2-=mi[i];r1-=mi[i];r2-=mi[i]; continue; } if ((r1&mi[i])&&(!(l2&mi[i]))) { ans+=mi[i]; r1-=mi[i]; if (l1&mi[i]) l1-=mi[i];else l1=0; if (r2&mi[i]) r2=mi[i]-1; } else if ((r2&mi[i])&&(!(l1&mi[i]))) { ans+=mi[i]; r2-=mi[i]; if (l2&mi[i]) l2-=mi[i];else l2=0; if (r1&mi[i]) r1=mi[i]-1; } } printf("%I64d\n",ans); } }