import time import sys #sys.setrecursionlimit(500000) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def TI(): return tuple(map(int,sys.stdin.readline().rstrip().split())) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip()) #for i, pi in enumerate(p): from collections import defaultdict,deque import bisect import itertools dic = defaultdict(int) T = I() for i in range(T): A,B,C,D = MI() if C > D: C,D = D,C A,B = B,A ans = float('inf') if A < B <= C < D or A < C <= B < D: ans = 0 if A > C: ans += C+1 else: ans += C-A if B > D: ans += D+1 else: ans += D-B print(ans) continue if B < A < C < D or B <= C < A <= D or C < A <= B <= D or C <= B <= A <= D or B <= C <= D <= A or C <= B <= D <= A: print(D-B+C+1) continue else: if C <= A <= D <= B and C == 1: print(C+1+D+2) continue #if C <= D <= A <= B or C<= D <= B <= A or A<= C <= D <= B or C<= B<= D <= A: print(C+1+D+1) continue