import sys import math import bisect import heapq from collections import deque, defaultdict #160427717982164055zq # ------------------------------------------------- def ST(): return input().rstrip() def IN(): return int(input()) def ML(typ=int): return [typ(x) for x in input().split()] def IM(): return ML() def IL(): return ML() mod = 998244353 def mod_inv(a, mod): return pow(a, mod-2, mod) def mod_div(x, y, mod): inv = mod_inv(y, mod) return (x*inv)%mod T = IN() # 岩井星人さん、ポケモンだったらしい。 for _ in range(T): a, b, c, d = IM() ans = 0 # Tが異なる場合、どちらかが合わせて上に行くのが最適 if b != d: ans += abs(b-d) b = max(b, d) d = max(b, d) # 「コストを2支払ってbitを下げる価値があるかどうか」を判定ればいいのかな if a > c: a, c = c, a a = a >> b c = c >> b #print(a, c, file = sys.stderr) if a == c: print(ans) continue for i in range(63): na, nc = a >> 1, c >> 1 #print(nc, na) if 2 + abs(nc-na) < c-a: ans += 2 a, c = na, nc else: ans += c-a break print(ans)