from collections import deque import random import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 def solve1(a, b, c, d): dist = [[inf] * 100 for _ in range(100)] dist[a][b] = 0 q = deque([(a, b)]) while q: i, j = q.popleft() if i == c and j == d: return dist[i][j] if i + 1 != j and i + 1 < 100 and dist[i + 1][j] > dist[i][j] + 1: dist[i + 1][j] = dist[i][j] + 1 q.append((i + 1, j)) if j + 1 != i and j + 1 < 100 and dist[i][j + 1] > dist[i][j] + 1: dist[i][j + 1] = dist[i][j] + 1 q.append((i, j + 1)) if j != 0 and dist[0][j] > dist[i][j] + 1: dist[0][j] = dist[i][j] + 1 q.append((0, j)) if i != 0 and dist[i][0] > dist[i][j] + 1: dist[i][0] = dist[i][j] + 1 q.append((i, 0)) def dijkstra(s, n, graph): INF = 10 ** 18 import heapq dist = [INF] * n dist[s] = 0 bef = [0] * n bef[s] = s hq = [(0, s)] heapq.heapify(hq) visit = [False] * n while hq: c, v = heapq.heappop(hq) visit[v] = True if c > dist[v]: continue for to, cost in graph[v]: if visit[to] == False and dist[v] + cost < dist[to]: dist[to] = cost + dist[v] bef[to] = v heapq.heappush(hq, (dist[to], to)) return dist, bef def solve2(a, b, c, d): ind = {} i = 0 for v in [0, 1, 2, a, b, c, d]: for u in [0, 1, 2, a, b, c, d]: if u != v: ind[u, v] = i i += 1 graph = [[] for _ in range(i)] for u1, v1 in ind.keys(): i1 = ind[u1, v1] for u2, v2 in ind.keys(): i2 = ind[u2, v2] if u1 <= u2 and v1 <= v2 and i1 != i2 and ((u1 < v1 and u2 < v2) or (u1 > v1 and u2 > v2)): graph[i1].append((i2, abs(u2 - u1) + abs(v2 - v1))) if (u2 == 0 and v1 == v2) or (v2 == 0 and u1 == u2): graph[i1].append((i2, 1)) D, _ = dijkstra(ind[a, b], i, graph) return (D[ind[(c, d)]]) for _ in range(ii()): a, b, c, d = mi() print(solve2(a, b, c, d))