from heapq import * def solve(a, b, c, d): X = sorted({0, 1, 2, a, c}) Y = sorted({0, 1, 2, b, d}) mp = {} t = 0 for x in X: for y in Y: if x == y: continue mp[(x, y)] = t t += 1 edges = [[] for _ in range(t)] for x1 in X: for x2 in X: if x1 == x2: continue for y in Y: if y in [x1, x2]: continue if x2 == 0: edges[mp[(x1, y)]].append((mp[(x2, y)], 1)) elif x1 < y and y < x2: continue elif x1 > x2: continue else: edges[mp[(x1, y)]].append((mp[(x2, y)], x2 - x1)) X, Y = Y, X for x1 in X: for x2 in X: if x1 == x2: continue for y in Y: if y in [x1, x2]: continue if x2 == 0: edges[mp[(y, x1)]].append((mp[(y, x2)], 1)) elif x1 < y and y < x2: continue elif x1 > x2: continue else: edges[mp[(y, x1)]].append((mp[(y, x2)], x2 - x1)) dist = [1 << 60] * t dist[mp[(a, b)]] = 0 hq = [(0, mp[(a, b)])] while hq: dd, pos = heappop(hq) if dist[pos] < dd: continue for npos, cc in edges[pos]: if dist[npos] > dd + cc: dist[npos] = dd + cc heappush(hq, (dd + cc, npos)) return dist[mp[(c, d)]] for i in range(int(input())): ans = solve(*map(int, input().split())) print(ans)