Chef has two ranges [A, B] and [C, D]. Chef needs to find the number of integers that belong to at least one of the ranges.

Note: A range [P, Q] contains all the integers \{P, P+1, P+2, \dots, Q-1, Q\}.

------ Input Format ------ 

- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line containing 4 integers A, B, C, and D, as mentioned in the statement.

------ Output Format ------ 

For each test case, output on a new line, the number of integers that belong to at least one of the ranges.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ A ≤ B ≤ 8$
$1 ≤ C ≤ D ≤ 8$

----- Sample Input 1 ------ 
4
1 3 5 5
3 8 2 5
1 8 4 6
5 5 5 5

----- Sample Output 1 ------ 
4
7
8
1

----- explanation 1 ------ 
Test case $1$: There are $4$ integers that belong to at least one of the ranges. These are $1, 2, 3,$ and $5$.

Test case $2$: There are $7$ integers that belong to at least one of the ranges. These are $2, 3, 4, 5, 6, 7,$ and $8$.

Test case $3$: There are $8$ integers that belong to at least one of the ranges. These are $1, 2, 3, 4, 5, 6, 7,$ and $8$.

Test case $4$: There is only $1$ integer that belong to at least one of the ranges. That integer is $5$.

Source: codechef | Difficulty: EASY


Solutions:
t = int(input())
for _ in range(t):
	(a, b, c, d) = map(int, input().split())
	l1 = [i for i in range(a, b + 1)]
	l2 = [j for j in range(c, d + 1)]
	new = l1 + l2
	s = set(new)
	print(len(s))


from operator import length_hint
t = int(input())
for m in range(t):
	(a, c, z, g) = map(int, input().split())
	l = []
	for k in range(a, c + 1):
		l.extend([k])
	for j in range(z, g + 1):
		if j not in l:
			l.append([j])
	n = length_hint(l)
	print(n)


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	x = []
	for j in range(a, b + 1):
		if j not in x:
			x.append(j)
	for k in range(c, d + 1):
		if k not in x:
			x.append(k)
	print(len(x))


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	list = []
	for j in range(a, b + 1):
		list.append(j)
	for k in range(c, d + 1):
		list.append(k)
	print(len(set(list)))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	arr = []
	for i in range(a, b + 1):
		if i not in arr:
			arr.append(i)
	for j in range(c, d + 1):
		if j not in arr:
			arr.append(j)
	print(len(arr))


i = int(input())
for j in range(0, i):
	(a, b, c, d) = map(int, input().split())
	l1 = []
	for k in range(a, b + 1):
		l1.append(k)
	for k in range(c, d + 1):
		l1.append(k)
	t1 = set(l1)
	print(len(t1))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	s = set()
	for i in range(a, b + 1):
		s.add(i)
	for i in range(c, d + 1):
		s.add(i)
	print(len(s))


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	range1 = [False] * 9
	range2 = [False] * 9
	for j in range(a, b + 1):
		range1[j] = True
	for j in range(c, d + 1):
		range2[j] = True
	count = 0
	for j in range(1, 9):
		if range1[j] or range2[j]:
			count += 1
	print(count)


t = int(input())
while t > 0:
	(a, b, c, d) = [int(x) for x in input().split()]
	if c in range(a, b + 1):
		if d in range(a, b):
			print(b - a + 1)
		else:
			print(1 - a + d)
	elif a in range(c, d + 1):
		if b in range(c, d):
			print(d - c + 1)
		else:
			print(1 - c + b)
	else:
		print(b - a + d - c + 2)
	t = t - 1


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	l = set([x for x in range(a, b + 1)])
	l2 = set([x for x in range(c, d + 1)])
	print(len(l.union(l2)))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	set1 = set()
	set2 = set()
	for j in range(a, b + 1):
		set1.add(j)
	for k in range(c, d + 1):
		set2.add(k)
	print(len(set1.union(set2)))


T = int(input())
for _ in range(T):
	(A, B, C, D) = map(int, input().split())
	lstAB = [int(i) for i in range(A, B + 1)]
	lstCD = [int(i) for i in range(C, D + 1)]
	lst_add = lstAB + lstCD
	set_add = set(lst_add)
	print(len(set_add))


n = int(input())
for i in range(n):
	(a, b, c, d) = list(map(int, input().split()))
	maxi = max(a, b, c, d)
	mini = min(a, b, c, d)
	c1 = 0
	for j in range(mini, maxi + 1):
		if a <= j <= b or c <= j <= d:
			c1 += 1
	print(c1)


T = int(input())
for i in range(T):
	(A, B, C, D) = map(int, input().split())
	count = 0
	integers = set()
	for i in range(A, B + 1):
		integers.add(i)
	for i in range(C, D + 1):
		integers.add(i)
	print(len(integers))


q = int(input())
for p in range(q):
	(a, b, c, d) = map(int, input().split())
	l = []
	for i in range(a, b + 1):
		if i not in l:
			l.append(i)
	for j in range(c, d + 1):
		if j not in l:
			l.append(j)
	print(len(l))


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	lst1 = list(range(a, b + 1))
	lst2 = list(range(c, d + 1))
	for i in lst2:
		if i not in lst1:
			lst1.append(i)
	print(len(lst1))


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	l = []
	for i in range(a, b + 1):
		l.append(i)
	for i in range(c, d + 1):
		l.append(i)
	print(len(set(l)))


T = int(input())
for i in range(T):
	(A, B, C, D) = map(int, input().split())
	n1 = []
	n2 = []
	if A == B:
		n1.append(A)
	else:
		for i in range(A, B + 1):
			n1.append(i)
	if C == D:
		n2.append(C)
	else:
		for j in range(C, D + 1):
			n2.append(j)
	for i in n1:
		if i not in n2:
			n2.append(i)
	print(len(n2))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	l1 = [x for x in range(a, b + 1)]
	l2 = [x for x in range(c, d + 1)]
	ans = set()
	for i in l1:
		ans.add(i)
	for j in l2:
		ans.add(j)
	print(len(ans))


t = int(input())
for _ in range(t):
	(a, b, c, d) = map(int, input().split())
	result = 0
	if c <= a and d >= b:
		result = d - c + 1
	elif a <= c and b >= d:
		result = b - a + 1
	elif b < c or d < a:
		result = b - a + 1 + (d - c + 1)
	elif b >= c and d >= b:
		result = d - a + 1
	elif d >= a and b >= d:
		result = b - c + 1
	print(result)


t = int(input())
for _ in range(t):
	(a, b, c, d) = map(int, input().split())
	l = []
	for i in range(a, b + 1):
		l.append(i)
	for i in range(c, d + 1):
		if i not in l:
			l.append(i)
	print(len(l))


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	unique = []
	temp = a
	while temp <= b:
		if temp not in unique:
			unique.append(temp)
		temp += 1
	temp = c
	while temp <= d:
		if temp not in unique:
			unique.append(temp)
		temp += 1
	print(len(unique))


t = int(input())
for i in range(t):
	(A, B, C, D) = map(int, input().split())
	count = []
	for i in range(1, 9):
		if i >= A and i <= B:
			count.append(i)
		elif i >= C and i <= D:
			if i not in count:
				count.append(i)
	print(len(count))


T = int(input())
for tc in range(T):
	(a, b, c, d) = map(int, input().split())
	x = []
	for k in range(a, b + 1):
		x.append(k)
	for L in range(c, d + 1):
		x.append(L)
	print(len(set(x)))


i = int(input(''))
j = 0
while j < i:
	l1 = []
	l2 = []
	l = []
	n1 = input('')
	n = n1.split()
	A = int(n[0])
	B = int(n[1])
	C = int(n[2])
	D = int(n[3])
	l1 = list(range(A, B + 1))
	l2 = list(range(C, D + 1))
	l = l1 + l2
	s = set(l)
	print(len(s))
	j += 1


n = int(input())
i = 1
while i <= n:
	l = [int(x) for x in input().split()]
	set1 = set({})
	set2 = set({})
	for x in range(l[0], l[1] + 1):
		set1.add(x)
	for x in range(l[2], l[3] + 1):
		set2.add(x)
	print(len(set1.union(set2)))
	i = i + 1


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	x = []
	for i in range(a, b + 1):
		x.append(i)
	for j in range(c, d + 1):
		x.append(j)
	print(len(set(x)))


T = int(input())
for _ in range(T):
	(A, B, C, D) = map(int, input().split())
	print(len(set([i for i in range(A, B + 1)] + [i for i in range(C, D + 1)])))


N = int(input())
for j in range(N):
	(A, B, C, D) = map(int, input().split(' '))
	l1 = []
	for i in range(A, B + 1):
		l1.append(i)
	for i in range(C, D + 1):
		l1.append(i)
	print(len(set(l1)))


T = int(input())
for i in range(T):
	(A, B, C, D) = map(int, input().split(' '))
	S = set()
	for j in range(A, B + 1):
		S.add(j)
	for j in range(C, D + 1):
		S.add(j)
	print(len(S))


for i in range(int(input())):
	counter = 0
	range1 = []
	range2 = []
	unique = []
	(a, b, c, d) = map(int, input().split())
	for i in range(a, b + 1):
		range1.append(i)
	for i in range(c, d + 1):
		range2.append(i)
	unique = set(range1 + range2)
	print(len(unique))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	l = [i for i in range(a, b + 1)]
	l1 = [i for i in range(c, d + 1)]
	l2 = l + l1
	print(len(set(l2)))


t = int(input())
for _ in range(t):
	x = list(map(int, input().split()))
	(a, b, c, d) = x
	res = set()
	for i in range(a, b + 1):
		res.add(i)
	for i in range(c, d + 1):
		res.add(i)
	print(len(res))


n = int(input())
for _ in range(n):
	(a, b, c, d) = map(int, input().split())
	k = set()
	for i in range(a, b + 1):
		k.add(i)
	for j in range(c, d + 1):
		k.add(j)
	print(len(k))


t = int(input())
f = []
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	if b < c or d < a:
		r = b - a + 1 + d - c + 1
	else:
		low = min(a, b, c, d)
		high = max(a, b, c, d)
		r = high - low + 1
	print(r)


for i in range(int(input())):
	(A, B, C, D) = map(int, input().split())
	l = []
	count = 0
	for i in range(A, B + 1):
		l.append(i)
	for i in range(C, D + 1):
		l.append(i)
	S = set(l)
	L = list(S)
	for i in range(len(L)):
		count += 1
	print(count)


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	e = []
	f = []
	for i in range(a, b + 1):
		e.append(i)
	for j in range(c, d + 1):
		f.append(j)
	e = e + f
	e = set(e)
	print(len(e))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	count = 0
	l1 = set(range(a, b + 1))
	l2 = set(range(c, d + 1))
	print(len(l1 | l2))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	sett = []
	for j in range(a, b + 1):
		sett.append(j)
	for j in range(c, d + 1):
		sett.append(j)
	new = set(sett)
	print(len(new))


for _ in range(int(input())):
	a = list(map(int, input().split()))
	b = [i for i in range(a[0], a[1] + 1)]
	c = [i for i in range(a[2], a[3] + 1)]
	l = set(b + c)
	print(len(l))


t = int(input())
for i in range(0, t):
	(a, b, c, d) = map(int, input().split(' '))
	l = []
	for i in range(a, b + 1):
		l.append(i)
	for j in range(c, d + 1):
		l.append(j)
	for k in l:
		if l.count(k) > 1:
			for i in range(1, l.count(k)):
				l.remove(k)
	print(len(l))


t = int(input())
for w in range(t):
	l = list(map(int, input().split()))
	x = set()
	z = 0
	if l[0] > l[1]:
		for i in range(l[1], l[0] + 1):
			x.add(i)
	else:
		for i in range(l[0], l[1] + 1):
			x.add(i)
	if l[2] > l[3]:
		for i in range(l[3], l[2] + 1):
			x.add(i)
	else:
		for i in range(l[2], l[3] + 1):
			x.add(i)
	print(len(x))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	p = []
	for j in range(a, b + 1):
		p.append(j)
	for k in range(c, d + 1):
		p.append(k)
	print(len(set(p)))


t = int(input())
for i in range(t):
	(A, B, C, D) = list(map(int, input().split()))
	l = []
	for j in range(A, B + 1):
		l.append(j)
	for k in range(C, D + 1):
		l.append(k)
	print(len(set(l)))