// code template is in https://github.com/drken1215/algorithm/blob/master/template_minimum.cpp #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include using namespace std; //------------------------------// // Utility //------------------------------// using ll = long long; using i128 = __int128_t; using u128 = __uint128_t; using pint = pair; using pll = pair; using tll = array; using fll = array; using vint = vector; using vll = vector; using dint = deque; using dll = deque; using vvint = vector>; using vvll = vector>; using vpll = vector>; template using min_priority_queue = priority_queue, greater>; template inline bool chmax(S &a, T b) { return (a < b ? a = b, 1 : 0); } template inline bool chmin(S &a, T b) { return (a > b ? a = b, 1 : 0); } template inline auto maxll(S a, T b) { return max(ll(a), ll(b)); } template inline auto minll(S a, T b) { return min(ll(a), ll(b)); } template auto max(const T &a) { return *max_element(a.begin(), a.end()); } template auto min(const T &a) { return *min_element(a.begin(), a.end()); } template auto argmax(const T &a) { return max_element(a.begin(), a.end()) - a.begin(); } template auto argmin(const T &a) { return min_element(a.begin(), a.end()) - a.begin(); } template auto accum(const vector &a) { return accumulate(a.begin(), a.end(), T()); } template auto accum(const deque &a) { return accumulate(a.begin(), a.end(), T()); } #define REP(i, a) for (long long i = 0; i < (long long)(a); i++) #define REP2(i, a, b) for (long long i = a; i < (long long)(b); i++) #define RREP(i, a) for (long long i = (a)-1; i >= (long long)(0); --i) #define RREP2(i, a, b) for (long long i = (b)-1; i >= (long long)(a); --i) #define EB emplace_back #define PF push_front #define PB push_back #define MP make_pair #define FI first #define SE second #define ALL(x) x.begin(), x.end() #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl // input template istream& operator >> (istream &is, vector &P) { for (int i = 0; i < (int)P.size(); ++i) cin >> P[i]; return is; } template istream& operator >> (istream &is, deque &P) { for (int i = 0; i < (int)P.size(); ++i) cin >> P[i]; return is; } template istream& operator >> (istream &is, vector> &P) { for (int i = 0; i < (int)P.size(); ++i) cin >> P[i]; return is; } // output template ostream& operator << (ostream &s, const pair &P) { return s << '<' << P.first << ", " << P.second << '>'; } template ostream& operator << (ostream &s, const array &P) { return s << '<' << P[0] << "," << P[1] << '>'; } template ostream& operator << (ostream &s, const array &P) { return s << '<' << P[0] << "," << P[1] << "," << P[2] << '>'; } template ostream& operator << (ostream &s, const array &P) { return s << '<' << P[0] << "," << P[1] << "," << P[2] << "," << P[3] << '>'; } template ostream& operator << (ostream &s, const vector &P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template ostream& operator << (ostream &s, const deque &P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template ostream& operator << (ostream &s, const vector> &P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template ostream& operator << (ostream &s, const set &P) { for (auto it : P) { s << "<" << it << "> "; } return s; } template ostream& operator << (ostream &s, const multiset &P) { for (auto it : P) { s << "<" << it << "> "; } return s; } template ostream& operator << (ostream &s, const unordered_set &P) { for (auto it : P) { s << "<" << it << "> "; } return s; } template ostream& operator << (ostream &s, const map &P) { for (auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; } template ostream& operator << (ostream &s, const unordered_map &P) { for (auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; } void yes(bool a) { cout << (a ? "yes" : "no") << endl; } void YES(bool a) { cout << (a ? "YES" : "NO") << endl; } void Yes(bool a) { cout << (a ? "Yes" : "No") << endl; } const vector DX = {1, 0, -1, 0, 1, -1, 1, -1}; const vector DY = {0, 1, 0, -1, 1, -1, -1, 1}; // Edge Class template struct Edge { int from, to; T val; Edge() : from(-1), to(-1) { } Edge(int f, int t, T v = 1) : from(f), to(t), val(v) {} friend ostream& operator << (ostream& s, const Edge& e) { return s << e.from << "->" << e.to << "(" << e.val << ")"; } }; // graph class template struct Graph { int V, E; vector>> list; vector>> reversed_list; vector> id; // id[v][w] := the index of node w in G[v] // constructors Graph(int n = 0, int m = 0) : V(n), E(m), list(n), reversed_list(n), id(n) { } void init(int n = 0, int m = 0) { V = n, E = m; list.assign(n, vector>()); reversed_list.assign(n, vector>()); id.assign(n, unordered_map()); } Graph(const Graph&) = default; Graph& operator = (const Graph&) = default; // getters vector> &operator [] (int i) { return list[i]; } const vector> &operator [] (int i) const { return list[i]; } const vector> &get_rev_edges(int i) const { return reversed_list[i]; } const size_t size() const { return list.size(); } const void clear() { V = 0; list.clear(); } const void resize(int n) { V = n; list.resize(n); } Edge &get_edge(int u, int v) { assert(u >= 0 && u < list.size() && v >= 0 && v < list.size()); assert(id[u].count(v) && id[u][v] >= 0 && id[u][v] < list[u].size()); return list[u][id[u][v]]; } const Edge &get_edge(int u, int v) const { assert(u >= 0 && u < list.size() && v >= 0 && v < list.size()); assert(id[u].count(v) && id[u].at(v) >= 0 && id[u].at(v) < list[u].size()); return list[u][id[u].at(v)]; } // add edge void add_edge(int from, int to, T val = 1) { assert(0 <= from && from < list.size() && 0 <= to && to < list.size()); id[from][to] = (int)list[from].size(), list[from].push_back(Edge(from, to, val)); reversed_list[to].push_back(Edge(to, from, val)); } void add_bidirected_edge(int from, int to, T val = 1) { assert(0 <= from && from < list.size() && 0 <= to && to < list.size()); id[from][to] = (int)list[from].size(), list[from].push_back(Edge(from, to, val)); reversed_list[from].push_back(Edge(from, to, val)); if (from != to) { id[to][from] = (int)list[to].size(), list[to].push_back(Edge(to, from, val)); reversed_list[to].push_back(Edge(to, from, val)); } } // input / output friend istream& operator >> (istream &is, Graph &G) { for (int i = 0; i < G.E; i++) { int u, v; is >> u >> v, u--, v--; G.add_bidirected_edge(u, v); } return is; } friend ostream &operator << (ostream &os, const Graph &G) { os << endl; for (int i = 0; i < G.size(); ++i) { os << i << " -> "; for (int j = 0; j < G[i].size(); j++) { if (j) os << ", "; os << G[i][j].to << "(" << G[i][j].val << ")"; } os << endl; } return os; } }; // mod inv template constexpr T_VAL mod_inv(T_VAL a, T_MOD m) { T_VAL b = m, u = 1, v = 0; while (b > 0) { T_VAL t = a / b; a -= t * b, swap(a, b); u -= t * v, swap(u, v); } u %= m; if (u < 0) u += m; return u; } // modint template struct Fp { // inner value unsigned int val; // constructor constexpr Fp() : val(0) { } template constexpr Fp(T v) { long long tmp = (long long)(v % (long long)(get_umod())); if (tmp < 0) tmp += get_umod(); val = (unsigned int)(tmp); } template constexpr Fp(T v) { val = (unsigned int)(v % get_umod()); } constexpr long long get() const { return val; } constexpr static int get_mod() { return MOD; } constexpr static unsigned int get_umod() { return MOD; } // arithmetic operators constexpr Fp operator + () const { return Fp(*this); } constexpr Fp operator - () const { return Fp() - Fp(*this); } constexpr Fp operator + (const Fp &r) const { return Fp(*this) += r; } constexpr Fp operator - (const Fp &r) const { return Fp(*this) -= r; } constexpr Fp operator * (const Fp &r) const { return Fp(*this) *= r; } constexpr Fp operator / (const Fp &r) const { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp &r) { val += r.val; if (val >= get_umod()) val -= get_umod(); return *this; } constexpr Fp& operator -= (const Fp &r) { val -= r.val; if (val >= get_umod()) val += get_umod(); return *this; } constexpr Fp& operator *= (const Fp &r) { unsigned long long tmp = val; tmp *= r.val; val = (unsigned int)(tmp % get_umod()); return *this; } constexpr Fp& operator /= (const Fp &r) { return *this = *this * r.inv(); } constexpr Fp pow(long long n) const { assert(n >= 0); Fp res(1), mul(*this); while (n) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } constexpr Fp inv() const { if (PRIME) { assert(val); return pow(get_umod() - 2); } else { assert(val); return mod_inv((long long)(val), get_umod()); } } // other operators constexpr bool operator == (const Fp &r) const { return this->val == r.val; } constexpr bool operator != (const Fp &r) const { return this->val != r.val; } constexpr bool operator < (const Fp &r) const { return this->val < r.val; } constexpr bool operator > (const Fp &r) const { return this->val > r.val; } constexpr bool operator <= (const Fp &r) const { return this->val <= r.val; } constexpr bool operator >= (const Fp &r) const { return this->val >= r.val; } constexpr Fp& operator ++ () { ++val; if (val == get_umod()) val = 0; return *this; } constexpr Fp& operator -- () { if (val == 0) val = get_umod(); --val; return *this; } constexpr Fp operator ++ (int) { Fp res = *this; ++*this; return res; } constexpr Fp operator -- (int) { Fp res = *this; --*this; return res; } friend constexpr istream& operator >> (istream &is, Fp &x) { long long tmp = 1; is >> tmp; tmp = tmp % (long long)(get_umod()); if (tmp < 0) tmp += get_umod(); x.val = (unsigned int)(tmp); return is; } friend constexpr ostream& operator << (ostream &os, const Fp &x) { return os << x.val; } friend constexpr Fp pow(const Fp &r, long long n) { return r.pow(n); } friend constexpr Fp inv(const Fp &r) { return r.inv(); } }; // Binomial coefficient template struct BiCoef { vector fact_, inv_, finv_; constexpr BiCoef() {} constexpr BiCoef(int n) : fact_(n, 1), inv_(n, 1), finv_(n, 1) { init(n); } constexpr void init(int n) { fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1); int MOD = fact_[0].get_mod(); for(int i = 2; i < n; i++){ fact_[i] = fact_[i-1] * i; inv_[i] = -inv_[MOD%i] * (MOD/i); finv_[i] = finv_[i-1] * inv_[i]; } } constexpr mint com(int n, int k) const { if (n < k || n < 0 || k < 0) return 0; return fact_[n] * finv_[k] * finv_[n-k]; } constexpr mint fact(int n) const { if (n < 0) return 0; return fact_[n]; } constexpr mint inv(int n) const { if (n < 0) return 0; return inv_[n]; } constexpr mint finv(int n) const { if (n < 0) return 0; return finv_[n]; } // 1 / (1 - x)^n の r 次の係数 constexpr mint negcom(int n, int r) const { return com(n + r - 1, r); } }; //------------------------------// // Solver //------------------------------// // int 128 i128 to_integer(const string &s) { i128 res = 0; for (auto c : s) { if (isdigit(c)) res = res * 10 + (c - '0'); } if (s[0] == '-') res *= -1; return res; } istream& operator >> (istream &is, i128 &x) { string s; is >> s; x = to_integer(s); return is; } ostream& operator << (ostream &os, const i128 &x) { i128 ax = (x >= 0 ? x : -x); char buffer[128]; char *d = end(buffer); do { --d; *d = "0123456789"[ax % 10]; ax /= 10; } while (ax != 0); if (x < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); } return os; } i128 gcd(i128 a, i128 b) { if (a < 0) a = -a; if (b < 0) b = -b; if (b == 0) return a; else return gcd(b, a % b); } void solve() { ll sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; ll res = (ll)(1LL << 62); REP(d, 62) { ll tate = abs(d - sy) + abs(d - ty); ll width = 1LL << d; ll sb = sx / width, tb = tx / width; ll yoko = abs(sb - tb); ll need = tate + yoko; chmin(res, need); //cout << d << ": " << tate << ", " << pll(sb, tb) << ": " << need << endl; } cout << res << endl; } int main() { ll T; cin >> T; while (T--) solve(); }