Chef likes inequalities. Please help him to solve next one.
Given four integers a, b, c, d. Find number of solutions x < y, where a ≤ x ≤ b and c ≤ y ≤ d and x, y integers.

-----Input-----
The first line contains an integer T denoting number of tests.
First line of each test case contains four positive integer numbers a, b, c and d.

-----Output-----
For each test case, output a single number each in separate line denoting number of integer solutions as asked in the problem.

-----Constraints-----
- 1 ≤ T ≤ 20 
- 1 ≤ a, b, c, d ≤ 106 

-----Subtasks-----
- Subtask #1: (30 points)  1 ≤ a, b, c, d ≤ 103.
- Subtask #2: (70 points)  Original constraints.

-----Example-----
Input:1
2 3 3 4

Output:3

Input:1
2 999999 1 1000000

Output:499998500001

Difficulty: UNKNOWN_DIFFICULTY

Starter code:

Solutions:
T = eval(input())
for i in range(T):
	(a, b, c, d) = list(map(int, input().split()))
	x = c - a
	n1 = b - a + 1
	n2 = d - c + 1
	s = 0
	if x <= 0:
		t = n2 - abs(x) - 1
		for j in range(t, max(0, d - b - 1), -1):
			s = s + j
	if x > 0:
		t = n2
		for j in range(x, max(0, c - b - 1), -1):
			s = s + t
		if c - b <= 0:
			for j in range(t - 1, max(0, d - b - 1), -1):
				s = s + j
	print(s)


import sys
ting = int(sys.stdin.readline())
for i in range(ting):
	m = list(map(int, sys.stdin.readline().split()))
	(a, b, c, d) = (m[0], m[1], m[2], m[3])
	count1 = 0
	i = a
	while i <= b:
		if i > d:
			break
		if i < c:
			count1 = count1 + d - c + 1
		if i >= c:
			count1 = count1 + d - i
		i = i + 1
	print(count1)


import sys
t = int(sys.stdin.readline())
for i in range(t):
	l = list(map(int, input().split()))
	(a, b, c, d) = (l[0], l[1], l[2], l[3])
	count = 0
	r = 1
	i = a
	while i <= b:
		if i > d:
			break
		if i < c:
			count = count + d - c + 1
		if i >= c:
			count = count + d - i
		i = i + 1
	print(count)


t = int(input())
while t > 0:
	t = t - 1
	(a, b, c, d) = list(map(int, input().split()))
	count = 0
	for x in range(a, b + 1):
		if x < c:
			count += d - c + 1
		elif x < d:
			count += d - x
		else:
			break
	print(count)


t = eval(input())
results = []
for a0 in range(t):
	(a, b, c, d) = [float(x) for x in input().split()]
	flag = [a, b]
	flag.sort()
	(a, b) = (flag[0], flag[1])
	flag = [c, d]
	flag.sort()
	(c, d) = (flag[0], flag[1])
	if c < a and d < a:
		results.append(0)
		continue
	if c > b:
		results.append(int((b - a + 1) * (d - c + 1)))
		continue
	if c == b:
		results.append(int((b - a + 1) * (d - c + 1) - 1))
		continue
	if c < b and d > b and (c > a):
		s = (c - a) * (d - c + 1) + (b - c + 1) / 2 * (d - b + (d - c))
		results.append(int(s))
		continue
	if c < b and d > b and (c < a):
		c = a + 1
		s = (c - a) * (d - c + 1) + (b - c + 1) / 2 * (d - b + (d - c))
		results.append(int(s))
		continue
	if c < b and d < b and (c > a):
		s = (c - a) * (d - c + 1) + (d - c) / 2 * (d - c + 1)
		results.append(int(s))
		continue
	if c < a and d < b:
		c = a + 1
		s = (c - a) * (d - c + 1) + (d - c) / 2 * (d - c + 1)
		results.append(int(s))
		continue
for a1 in range(len(results)):
	print(results[a1])


t = int(input())
for i in range(t):
	inp = str(input()).split()
	a = int(inp[0])
	b = int(inp[1])
	c = int(inp[2])
	d = int(inp[3])
	count = 0
	count1 = 0
	if a >= d or a > b or c > d:
		pass
	n = d - c + 1
	n2 = d - b - 1
	c11 = (c - a - 1) * n
	c12 = (b - a - 1) * n
	c1 = min(c11, c12)
	c2 = n * (n + 1) / 2 - n2 * (n2 + 1) / 2
	c2 = max(c2, 0)
	count = c1 + c2
	n1 = max(d - a, 0)
	n2 = max(d - b - 1, 0)
	n3 = max(c - a - 1, 0)
	n4 = max(c - b - 2, 0)
	c1 = n1 * (n1 + 1) / 2
	c2 = n2 * (n2 + 1) / 2
	c3 = n3 * (n3 + 1) / 2
	c4 = n4 * (n4 + 1) / 2
	count1 = c1 - c2 - c3 + c4
	print(count1)


t = eval(input())
while t:
	(a, b, c, d) = list(map(int, input().split()))
	ans = 0
	if c <= d:
		for x in range(a, b + 1):
			y = x + 1
			if c > y:
				y = c
			if d - y >= 0:
				ans += d - y + 1
	print(ans)
	t -= 1


t = eval(input())
for test in range(t):
	l = [int(i) for i in input().split()]
	a = l[0]
	b = l[1]
	c = l[2]
	d = l[3]
	ans = 0
	for i in range(a, b + 1):
		if i >= c and i <= d:
			ans += d - i
		elif i < c:
			ans += d - c + 1
	print(ans)


tc = int(input())
for i in range(tc):
	ans = 0
	(a, b, c, d) = list(map(int, input().split()))
	for j in range(a, b + 1):
		if j < c and j < d:
			ans += d - c + 1
		if j >= c and j < d:
			ans += d - j
		if j > d:
			break
	print(ans)


T = int(input())
l = []
for i in range(T):
	l += [[int(j) for j in input().split()]]
l1 = []
for i in l:
	(a, b, c, d) = tuple(i)
	if a >= d:
		l1 += [0]
	elif b < c:
		l1 += [(b - a + 1) * (d - c + 1)]
	elif c <= a <= d <= b:
		n = d - a
		l1 += [n * (n + 1) / 2]
	elif c <= a <= b <= d:
		l1 += [(d - a) * (d - a + 1) / 2 - (d - b - 1) * (d - b) / 2]
	elif a < c <= d <= b:
		l1 += [(d - c + 1) * (c - a) + (d - c) * (d - c + 1) / 2]
	elif a < c <= b <= d:
		l1 += [(d - c + 1) * (c - a) + (d - c) * (d - c + 1) / 2 - (d - b - 1) * (d - b) / 2]
	else:
		l1 += [0]
for i in l1:
	print(i)


t = int(input())
while t > 0:
	s = 0
	g = 0
	p = 0
	(a, b, c, d) = input().strip().split(' ')
	a = int(a)
	b = int(b)
	c = int(c)
	d = int(d)
	for i in range(a, b + 1):
		if d > i:
			p = d - i
			s = s + p
		if c > i:
			g = c - i
			s = s - g + 1
	print(s)
	t -= 1