#include #include #include #include #include #include #include #include #include #include #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int MN = 500000 + 10; const int ME = 100000 + 10; const int mod = 1000000007; typedef long long LL; typedef unsigned long long ULL; const double pi = acos(-1.0); const int Intmax = (~(1 << 31)); const int Intmin = (1 << 31); const LL LLmax = (~(1LL << 63)); const LL LLmin = (1LL << 63); const ULL ULLmax = (~(0ULL)); int ans[75],a[75],b[75],c[75],d[75]; LL res; void dfs(int l,int flag1,int flag2,int cl,int dl){ if(l==0){ int i; LL tmp=0; for(i=64;i>=1;i--){ tmp*=2; tmp+=ans[i]; } res=max(res,tmp); return ; } int a1,a2; if(cl||dl){ ans[l]=1; dfs(l-1,flag1,flag2,cl,dl); return ; } if(flag1==0){ if(a[l]==b[l]){ a1=a[l]; } else a1=2; } else if(flag1==1){ if(b[l]==1) a1=2; else a1=0; } else{ if(a[l]==0) a1=2; else a1=1; } if(flag2==0){ if(c[l]==d[l]){ a2=c[l]; } else a2=2; } else if(flag2==1){ if(d[l]==1) a2=2; else a2=0; } else{ if(c[l]==0) a2=2; else a2=1; } if((a1==1||a1==0)&&(a2==1||a2==0)){ ans[l]=a1^a2; dfs(l-1,flag1,flag2,cl,dl); } else{ if((a1==1||a1==0)&&a2==2){ ans[l]=1; int tmp; if(a1==1) tmp=2; else tmp=1; if(flag2==1&&a1==1) dfs(l-1,flag1,tmp,cl,1); else if(flag2==2&&a1==0) dfs(l-1,flag1,tmp,cl,1); else dfs(l-1,flag1,tmp,cl,dl); } else if((a2==1||a2==0)&&a1==2){ ans[l]=1; int tmp; if(a2==1) tmp=2; else tmp=1; if(flag1==1&&a2==1) dfs(l-1,tmp,flag2,1,dl); else if(flag1==2&&a2==0) dfs(l-1,tmp,flag2,1,dl); else dfs(l-1,tmp,flag2,cl,dl); } else{ int tmp1=1,tmp2=2; ans[l]=1; if(flag1==0&&flag2==0){ dfs(l-1,tmp1,tmp2,cl,dl); dfs(l-1,tmp2,tmp1,cl,dl); } else dfs(l-1,flag1,flag2,1,1); } } } int main() { #ifndef ONLINE_JUDGE freopen("1.cpp", "r", stdin); #endif // ONLINE_JUDGE int t; scanf("%d",&t); while(t--){ LL A,B,C,D; scanf("%I64d%I64d%I64d%I64d",&A,&B,&C,&D); memset(ans,0,sizeof(ans)); memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); memset(d,0,sizeof(d)); int l=1; while(A){ if(A&1) a[l]=1; A>>=1; l++; } l=1; while(B){ if(B&1) b[l]=1; B>>=1; l++; } l=1; while(C){ if(C&1) c[l]=1; C>>=1; l++; } l=1; while(D){ if(D&1) d[l]=1; D>>=1; l++; } int i; res=0; dfs(64,0,0,0,0); printf("%I64d\n",res); } return 0; }