#include #include using namespace std ; typedef long long LL ; const int MAXN = 300005 ; LL A , B , C , D , ans ; void dfs ( int cur , LL x , LL y , LL v ) { if ( cur == -1 ) { if ( x >= A && x <= B && y >= C && y <= D ) ans = max ( ans , v ) ; return ; } if ( ( v ^ ( 1LL << cur ) ) <= ans ) return ; LL x1 = x ^ ( 1LL << cur ) ; LL y1 = y ^ ( 1LL << cur ) ; if ( x > B || y > D ) return ; if ( x + ( 1LL << cur + 1 ) > A && y + ( 1LL << cur + 1 ) > C ) { if ( x1 <= B ) dfs ( cur - 1 , x1 , y , v ^ ( 1LL << cur ) ) ; if ( y1 <= D ) dfs ( cur - 1 , x , y1 , v ^ ( 1LL << cur ) ) ; if ( x1 <= B && y1 <= D ) dfs ( cur - 1 , x1 , y1 , v ) ; dfs ( cur - 1 , x , y , v ) ; } } void solve () { ans = -1 ; scanf ( "%I64d%I64d%I64d%I64d" , &A , &B , &C , &D ) ; dfs ( 61 , 0 , 0 , 0 ) ; printf ( "%I64d\n" , ans ) ; } int main () { int T ; scanf ( "%d" , &T ) ; for ( int i = 1 ; i <= T ; ++ i ) { solve () ; } return 0 ; }