#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) #define MEM(a,b) memset(a,b,sizeof(a)) #define MP(a,b) make_pair(a,b) #define PB push_back typedef long long ll; typedef pair pii; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int MAXN = 100010; int T; ll a,b,c,d; int sa[100],sb[100],sc[100],sd[100]; ll dp[100][2][2][2][2]; inline void Magic(ll &a,ll b){ if(a < b) a = b; } int main(){ ios::sync_with_stdio(false); scanf("%d",&T); while(T--){ memset(dp,-1,sizeof(dp)); memset(sa,0,sizeof(sa)); memset(sb,0,sizeof(sb)); memset(sc,0,sizeof(sc)); memset(sd,0,sizeof(sd)); cin >> a >> b >> c >> d; for(int i = 1; i <= 63; ++i){ if((1LL << (i - 1)) & a) sa[i] = 1; if((1LL << (i - 1)) & b) sb[i] = 1; if((1LL << (i - 1)) & c) sc[i] = 1; if((1LL << (i - 1)) & d) sd[i] = 1; } dp[63][0][0][0][0] = 0; for(int i = 63; i >= 1; --i){ for(int fa = 0; fa <= 1; ++fa){ for(int fb = 0; fb <= 1; ++fb){ for(int fc = 0; fc <= 1; ++fc){ for(int fd = 0; fd <= 1; ++fd){ if(dp[i][fa][fb][fc][fd] == -1) continue; // x : 1 , y : 0 if((sb[i] || fb) && (!sc[i] || fc)){ Magic(dp[i - 1][fa|(!sa[i])][fb][fc][fd|sd[i]], dp[i][fa][fb][fc][fd] + (1LL << (i - 1))); } // x : 0 , y : 1 if((!sa[i] || fa) && (sd[i] || fd)){ Magic(dp[i - 1][fa][fb|sb[i]][fc|(!sc[i])][fd], dp[i][fa][fb][fc][fd] + (1LL << (i - 1))); } // x : 0 , y : 0 if((!sa[i] || fa) && (!sc[i] || fc)){ Magic(dp[i - 1][fa][fb|sb[i]][fc][fd|sd[i]], dp[i][fa][fb][fc][fd]); } // x : 1 , y : 1 if((sb[i] || fb) && (sd[i] || fd)){ Magic(dp[i - 1][fa|(!sa[i])][fb][fc|(!sc[i])][fd], dp[i][fa][fb][fc][fd]); } } } } } } ll ans = 0; for(int fa = 0; fa <= 1; ++fa){ for(int fb = 0; fb <= 1; ++fb){ for(int fc = 0; fc <= 1; ++fc){ for(int fd = 0; fd <= 1; ++fd){ ans = max(ans,dp[0][fa][fb][fc][fd]); } } } } cout << ans << endl; } return 0; }