read_line.to_i.times do puts solve() end def solve sx, sy, tx, ty = read_line.split.map(&.to_i64) if sy > ty sx, tx = tx, sx sy, ty = ty, sy end y = ty ans = 1i64 << 60 while true ans = {ans, y - ty + y - sy + ((sx >> y) - (tx >> y)).abs}.min break if sx >> (y - ty) == tx >> (y - ty) y += 1 end ans end