#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair PLL; #define MP make_pair const int N = 100; ll mi[N]; map , int>, ll > mp; ll dfs(ll a, ll b, ll c, ll d, int p) { if (p == -1) return 0; if (a == 0 && b == mi[p + 1] - 1) return mi[p + 1] - 1; if (c == 0 && d == mi[p + 1] - 1) return mi[p + 1] - 1; if (mp.count(MP(MP(MP(a, b), MP(c, d)), p))) return mp[MP(MP(MP(a, b), MP(c, d)), p)]; ll re = 0; bool flg = 0; if ((b & mi[p]) && (!(c & mi[p]))) { ll A = a, B = b, C = c, D = d; if (a & mi[p]) A -= mi[p], B -= mi[p]; else A = 0, B -= mi[p]; if (!(d & mi[p])) ; else D = mi[p] - 1; re = max(re, dfs(A, B, C, D, p - 1) + mi[p]); flg = 1; } if (!(a & mi[p]) && (d & mi[p])) { ll A = a, B = b, C = c, D = d; if (!(b & mi[p])) ; else B = mi[p] - 1; if (c & mi[p]) C -= mi[p], D -= mi[p]; else C = 0, D -= mi[p]; re = max(re, dfs(A, B, C, D, p - 1) + mi[p]); flg = 1; } if (!flg) re = max(re, dfs(a % mi[p], b % mi[p], c % mi[p], d % mi[p], p - 1)); return mp[MP(MP(MP(a, b), MP(c, d)), p)] = re; } void Main() { ll a, b, c, d; scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d); mp.clear(); printf("%I64d\n", dfs(a, b, c, d, 60)); } int main() { int T; scanf("%d", &T); mi[0] = 1; for (int i = 1; i <= 61; i++) mi[i] = mi[i - 1] * 2; while (T--) Main(); }