Polycarp lives on the coordinate axis $Ox$ and travels from the point $x=a$ to $x=b$. It moves uniformly rectilinearly at a speed of one unit of distance per minute.

On the axis $Ox$ at the point $x=c$ the base station of the mobile operator is placed. It is known that the radius of its coverage is $r$. Thus, if Polycarp is at a distance less than or equal to $r$ from the point $x=c$, then he is in the network coverage area, otherwise — no. The base station can be located both on the route of Polycarp and outside it.

Print the time in minutes during which Polycarp will not be in the coverage area of the network, with a rectilinear uniform movement from $x=a$ to $x=b$. His speed — one unit of distance per minute.


-----Input-----

The first line contains a positive integer $t$ ($1 \le t \le 1000$) — the number of test cases. In the following lines are written $t$ test cases.

The description of each test case is one line, which contains four integers $a$, $b$, $c$ and $r$ ($-10^8 \le a,b,c \le 10^8$, $0 \le r \le 10^8$) — the coordinates of the starting and ending points of the path, the base station, and its coverage radius, respectively.

Any of the numbers $a$, $b$ and $c$ can be equal (either any pair or all three numbers). The base station can be located both on the route of Polycarp and outside it.


-----Output-----

Print $t$ numbers — answers to given test cases in the order they are written in the test. Each answer is an integer — the number of minutes during which Polycarp will be unavailable during his movement.


-----Example-----
Input
9
1 10 7 1
3 3 3 0
8 2 10 4
8 2 10 100
-10 20 -17 2
-3 2 2 0
-3 1 2 0
2 3 2 3
-1 3 -2 2

Output
7
0
4
0
30
5
4
0
3



-----Note-----

The following picture illustrates the first test case.  [Image] Polycarp goes from $1$ to $10$. The yellow area shows the coverage area of the station with a radius of coverage of $1$, which is located at the point of $7$. The green area shows a part of the path when Polycarp is out of coverage area.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Implementation


Solutions:
T = int(input())
for test in range(T):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if c - r > b or c + r < a:
		print(b - a)
	else:
		bottom = max(min(c - r, b) - a, 0)
		upper = max(b - max(c + r, a), 0)
		time = bottom + upper
		print(time)


import math
mas = []
n = int(input())
for i in range(0, n):
	(a, b, c, r) = list(map(int, input().split()))
	if b < a:
		(a, b) = (b, a)
	x = b - a
	if c - r > a and c + r < b:
		x = x - 2 * r
	if c - r <= a and c + r >= b:
		x = 0
	if c - r <= a and c + r < b:
		x = x - (c + r - a)
	if c - r > a and c + r >= b:
		x = x - (b - (c - r))
	if c + r < a and c + r < b:
		x = b - a
	if c - r > a and c - r > b:
		x = b - a
	if r == 0:
		x = b - a
	mas.append(x)
	mas[i] = max(0, mas[i])
for i in range(n):
	print(mas[i])


def check():
	(a, b, c, r) = map(int, input().split())
	L = c - r
	R = c + r
	start = max(L, min(a, b))
	end = min(R, max(a, b))
	res = abs(a - b) - max(0, end - start)
	return res
for i in range(int(input())):
	print(check())


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	total = b - a
	right = c + r
	left = c - r
	if c < a:
		covered = max(0, right - a)
	elif c > b:
		covered = max(0, b - left)
	else:
		covered = min(b, right) - max(a, left)
	print(max(total - covered, 0))


for tc in range(int(input())):
	(a, b, c, r) = map(int, input().split(' '))
	if a > b:
		(a, b) = (b, a)
	l = c - r
	r = c + r
	temp = b - a
	if a >= l and b <= r:
		temp = 0
	elif b <= l and b <= r or (l <= a and r <= a):
		temp = temp
	elif l <= b and b <= r:
		temp = temp - (b - l)
	elif a <= l and r <= b:
		temp = temp - (r - l)
	elif l <= a and a <= r:
		temp = temp - (r - a)
	print(temp)


import sys
input = lambda : sys.stdin.readline()
for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	a1 = max(a, c - r)
	b1 = min(b, c + r)
	print(b - a - max(0, b1 - a1))


def temporarilyUnavailableSingle(a, b, c, r):
	minLimit = min(a, b)
	maxLimit = max(a, b)
	a = minLimit
	b = maxLimit
	count = 0
	exclude = 0
	first = c - r
	second = c + r
	diff = b - a
	if first < a < b < second:
		count = 0
	if first <= a <= second and (not b < second):
		exclude = second - a
		count = diff - exclude
	if first <= b <= second and (not first <= a <= second):
		exclude = b - first
		count = diff - exclude
	if a <= first and second <= b:
		exclude = second - first
		count = diff - exclude
	elif first >= b:
		count = diff
	elif second <= a:
		count = diff
	return count

def temporarilyUnavailable(givenInput):
	input = givenInput.split('\n')
	input = input[1:]
	result = ''
	for i in range(len(input)):
		singleLine = input[i]
		singleLine = singleLine.split()
		a = singleLine[0]
		b = singleLine[1]
		c = singleLine[2]
		r = singleLine[3]
		a = eval(a)
		b = eval(b)
		c = eval(c)
		r = eval(r)
		singleResult = temporarilyUnavailableSingle(a, b, c, r)
		if i < len(input) - 1:
			result = result + str(singleResult) + '\n'
		else:
			result = result + str(singleResult)
	print(result)
n = eval(input())
givenInput = str(n) + '\n'
for i in range(n):
	singleLine = input()
	if i == n - 1:
		givenInput += singleLine
		continue
	givenInput += singleLine + '\n'
temporarilyUnavailable(givenInput)


exec(int(input()) * '*t,c,r=map(int,input().split());a,b=sorted(t);print(b-a-max(0,min(b,c+r)-max(a,c-r)));')


import sys
import collections
from collections import Counter
import itertools
import math
import timeit
input = sys.stdin.readline

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
ans = []
for _ in range(t):
	(a, b, c, r) = mi()
	if a > b:
		(a, b) = (b, a)
	l = max(c - r, a)
	r = min(c + r, b)
	print(b - a - max(0, r - l))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	r1 = c + r
	r2 = c - r
	st = max(r2, min(a, b))
	ed = min(r1, max(a, b))
	print(abs(b - a) - max(0, ed - st))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = sorted((a, b))
	lc = c - r
	rc = c + r
	if a <= lc <= rc <= b:
		print(b - a - 2 * r)
	elif lc <= a <= rc <= b:
		print(b - rc)
	elif a <= lc <= b <= rc:
		print(lc - a)
	elif lc <= a <= b <= rc:
		print(0)
	elif lc <= rc <= a or b <= lc <= rc:
		print(b - a)


T = int(input())
for i in range(T):
	x = list(map(int, input().split()))
	(a, b, c, r) = (x[0], x[1], x[2], x[3])
	up = c + r
	low = c - r
	t = 0
	if c <= a and c <= b:
		if b >= a:
			if up <= a:
				t = b - a
			elif up >= b:
				t = 0
			else:
				t = b - up
		elif up <= b:
			t = a - b
		elif up >= a:
			t = 0
		else:
			t = a - up
	elif c >= a and c >= b:
		if b >= a:
			if low >= b:
				t = b - a
			elif low <= a:
				t = 0
			else:
				t = low - a
		elif low >= a:
			t = a - b
		elif low <= b:
			t = 0
		else:
			t = low - b
	elif b >= a:
		if up >= b and low <= a:
			t = 0
		elif up >= b:
			t = low - a
		elif low <= a:
			t = b - up
		else:
			t = b - up + (low - a)
	elif up >= a and low <= b:
		t = 0
	elif up >= a:
		t = low - b
	elif low <= b:
		t = a - up
	else:
		t = a - up + (low - b)
	print(t)


num = int(input())
for x in range(num):
	(a, b, c, r) = map(int, input().split(' '))
	print(max(a, b) - min(a, b) - max(0, min(c + r, max(a, b)) - max(c - r, min(a, b))))


n = int(input())
matrix = []
for i in range(n):
	num = list(map(int, input().split()))
	matrix.append(num)
for i in range(n):
	if matrix[i][0] <= matrix[i][1]:
		a = matrix[i][0]
		b = matrix[i][1]
	else:
		a = matrix[i][1]
		b = matrix[i][0]
	end1 = matrix[i][2] - matrix[i][3]
	end2 = matrix[i][2] + matrix[i][3]
	count = 0
	if end2 > b and a < end1 and (end1 < b):
		count += end1 - a
	elif end1 < a and b > end2 and (end2 > a):
		count = b - end2
	elif a >= end1 and b <= end2:
		count = 0
	elif a <= end1 and b >= end2:
		count = b - a - (end2 - end1)
	else:
		count = b - a
	print(count)


n = int(input())
for i in range(n):
	res = 0
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	if c > a and c < b:
		res = b - a - 2 * r + max(0, c + r - b) + max(0, a - c + r)
		print(max(0, res))
	elif c <= a:
		if c + r <= a:
			print(b - a)
		else:
			print(max(0, b - a - r + (a - c)))
	elif c - r >= b:
		print(b - a)
	else:
		print(max(0, b - a - r + (c - b)))


for case in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(c, d) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	if b <= c or d <= a:
		print(b - a)
	else:
		comon = 0
		left = max(a, c)
		right = min(b, d)
		comon = right - left
		comon = b - a - comon
		print(comon)


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	(a, b, c, r) = invr()
	if a > b:
		(a, b) = (b, a)
	if c <= a:
		print(max(0, b - max(a, c + r)))
	elif c >= b:
		print(max(0, min(b, c - r) - a))
	else:
		print(max(0, c - r - a) + max(0, b - (c + r)))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if c >= a and b >= c:
		c1 = c + r
		c2 = c - r
		if c + r >= b:
			c1 = b
		if c - r <= a:
			c2 = a
		print(b - a - (c1 - c2))
	elif c > b:
		if c - r <= b and c - r >= a:
			print(c - r - a)
		elif c - r > b:
			print(b - a)
		elif c - r < a:
			print(0)
	elif c < a:
		if c + r >= a and c + r <= b:
			print(b - (c + r))
		elif c + r < a:
			print(b - a)
		elif c + r > b:
			print(0)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	time_out = 0
	r1 = c - r
	r2 = c + r
	if max(a, b) < r1 or min(a, b) > r2:
		time_out += max(a, b) - min(a, b)
	if min(a, b) < r1:
		time_out += r1 - min(a, b)
	if max(a, b) > r2:
		time_out += max(a, b) - r2
	print(min(time_out, max(a, b) - min(a, b)))


import math
t = int(input())
for i in range(0, t):
	(a, b, c, r) = map(int, input().split())
	L = max(min(a, b), c - r)
	R = min(max(a, b), c + r)
	len = abs(a - b)
	print(len - max(0, R - L))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ans = min(b - a, max(0, c - r - a) + max(0, b - c - r))
	print(ans)


t = int(input())
ans = []
for i in range(t):
	not_covered = 0
	string = input()
	arr = string.split(' ')
	a = int(arr[0])
	b = int(arr[1])
	c = int(arr[2])
	r = int(arr[3])
	covered_left = c - r
	covered_right = c + r
	if a > b:
		(a, b) = (b, a)
	if r == 0 or covered_right < a or b < covered_left:
		not_covered = b - a
	elif covered_left <= a <= covered_right and covered_right >= b or a == b:
		not_covered = 0
	elif a <= covered_left and b >= covered_right:
		not_covered = covered_left - a + b - covered_right
	elif a <= covered_left and b <= covered_right:
		not_covered = covered_left - a
	elif covered_left <= a <= covered_right <= b:
		not_covered = b - covered_right
	ans.append(not_covered)
for j in range(len(ans)):
	print(ans[j], end='\n')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(a, b, c, r) = sep()
	(a, b) = (min(a, b), max(a, b))
	a2 = [c - r, c + r]
	if a2[1] < a or a2[0] > b:
		print(b - a)
	else:
		inter = min(b, a2[1]) - max(a, a2[0])
		print(b - a - inter)
testcase(int(inp()))


n = int(input())
for i in range(n):
	(a, b, c, r) = [int(i) for i in input().split()]
	f = max(a, b)
	g = min(a, b)
	if c >= f:
		d = c - r
		if d in range(g, f + 1):
			print(d - g)
		elif d < g:
			print(0)
		else:
			print(f - g)
	elif c < f and c >= g:
		d = c - r
		e = c + r
		left = d - g
		if left < 0:
			left = 0
		right = f - e
		if right < 0:
			right = 0
		print(left + right)
	elif c < g:
		e = c + r
		if e <= g:
			print(f - g)
		elif e > g and e < f:
			print(f - e)
		else:
			print(0)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	print(min(b - a, max(c - r - a, 0) + max(b - c - r, 0)))


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	ll = c - r
	ul = c + r
	if a > b:
		t = a
		a = b
		b = t
	ans = 0
	c = 0
	if ll <= b and ll >= a:
		ans += ll - a
		c += 1
	if ul <= b and ul >= a:
		ans += b - ul
		c += 1
	if c == 0:
		if ll <= a and ul >= b:
			ans = 0
		else:
			ans = b - a
	print(ans)


v = int(input())
for i in range(v):
	(fr, to, st, rd) = map(int, input().split())
	(fr, to) = (min(to, fr), max(fr, to))
	print(to - fr - max(min(to, st + rd) - max(fr, st - rd), 0))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	left = max(a, c - r)
	right = min(b, c + r)
	if c + r >= b:
		right = b
	if c + r <= a:
		right = a
		left = a
	if c - r >= b:
		left = b
	if c - r < a:
		left = a
	print(b - a - (right - left))


t = int(input())
for i in range(0, t):
	(a, b, c, r) = map(int, input().split())
	if b - a < 0:
		temp = a
		a = b
		b = temp
	c1 = c - r
	c2 = c + r
	if c1 == c2:
		ans = abs(b - a)
	elif c2 <= b:
		if c1 >= a:
			ans = abs(b - a) - (c2 - c1)
		elif c2 <= a:
			ans = abs(b - a)
		else:
			ans = abs(b - a) - (c2 - a)
	elif c1 >= a:
		if c1 >= b:
			ans = abs(b - a)
		else:
			ans = abs(b - a) - (b - c1)
	else:
		ans = 0
	if ans <= 0:
		print(0)
	else:
		print(ans)


test = int(input())
for i in range(test):
	(a, b, c, r) = [int(_) for _ in input().split()]
	if a > b:
		(a, b) = (b, a)
	answer = 0
	if c - r > a:
		answer += c - r - a
	if c + r < b:
		answer += b - (c + r)
	print(max(min(answer, b - a), 0))


t = int(input())
for i in range(t):
	k = 0
	(a, b, c, r) = [int(x) for x in input().split()]
	if c < min(a, b):
		k += abs(a - b) - max(0, r - abs(c - min(a, b)))
	elif max(a, b) < c:
		k += abs(a - b) - max(0, r - abs(c - max(a, b)))
	else:
		k += abs(a - b) - r - min(r, abs(c - a), abs(c - b))
	if k >= 0:
		print(k)
	else:
		print('0')


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b < c - r or a > c + r:
		print(b - a)
	else:
		print(max(c - r - a, 0) + max(b - c - r, 0))


n = int(input())
for kayra in range(0, n):
	alpha = input()
	alpha = alpha.split()
	x = int(alpha[0])
	y = int(alpha[1])
	t = int(alpha[2])
	r = int(alpha[3])
	a = min(x, y)
	b = max(x, y)
	c = min(t - r, t + r)
	d = max(t - r, t + r)
	if a > d or b < c:
		print(abs(a - b))
	else:
		k = max(a, c)
		l = min(b, d)
		m = abs(k - l)
		print(abs(a - b) - m)


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

def getVars():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def getStr():
	return input().strip()
t = getInt()
res = 0
for _ in range(t):
	(a, b, c, r) = getVars()
	if a > b:
		(a, b) = (b, a)
	res = b - a
	if not (c + r <= a or c - r >= b):
		if c <= a:
			res -= r - (a - c)
		elif c >= b:
			res -= r - (c - b)
		elif c - r <= a:
			res -= r + c - a
		elif c + r >= b:
			res -= r + b - c
		else:
			res -= r + r
	res = max(0, res)
	print(res)


t = input()
t = int(t)
out = []
for i in range(t):
	ab = [int(c) for c in input().split()]
	Rl = ab[2] - ab[3]
	Rr = ab[2] + ab[3]
	if Rl <= min(ab[1], ab[0]):
		if Rr >= max(ab[1], ab[0]):
			out.append(0)
		elif Rr <= min(ab[1], ab[0]):
			out.append(max(ab[1], ab[0]) - min(ab[1], ab[0]))
		else:
			out.append(max(ab[1], ab[0]) - Rr)
	elif Rl >= max(ab[1], ab[0]):
		out.append(max(ab[1], ab[0]) - min(ab[1], ab[0]))
	elif Rr >= max(ab[1], ab[0]):
		out.append(Rl - min(ab[1], ab[0]))
	else:
		out.append(max(ab[1], ab[0]) - min(ab[1], ab[0]) - Rr + Rl)
for i in range(t):
	print(out[i])


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if c - r > max(b, a) or c + r < min(a, b):
		print(max(b, a) - min(a, b))
	elif c + r >= max(b, a) and c - r <= min(a, b):
		print(0)
	elif c + r < max(b, a) and c - r > min(a, b):
		print(max(b, a) - min(a, b) - 2 * r)
	elif c + r >= max(b, a):
		print(c - r - min(a, b))
	else:
		print(max(b, a) - (c + r))


from sys import *
t = int(stdin.readline())
for _ in range(t):
	(x, y, c, r) = map(int, stdin.readline().split())
	a = min(x, y)
	b = max(x, y)
	x = c - r
	y = c + r
	ans = 0
	if a < x and b < x:
		ans += b - a
	elif b > y and a > y:
		ans += b - a
	else:
		if a < x:
			ans += abs(x - a)
		if b > y:
			ans += abs(y - b)
	print(ans)


from collections import defaultdict as dc
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def binarysearchforsolvingeqautions(a, i, l, r):
	while 1:
		mid = (l + r) / 2
		(p, q) = force(a, mid, i)
		if abs(p - q) < 1e-13:
			return mid
		elif p > q:
			l = mid
		else:
			r = mid

def bs(a, b):
	l = a
	r = b + 1
	x = b
	ans = 0
	while l < r:
		mid = (l + r) // 2
		if x | mid > ans:
			ans = x | mid
			l = mid + 1
		else:
			r = mid
	return ans

def digit(n):
	a = []
	while n > 0:
		a.append(n % 10)
		n = n // 10
	return a

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def opt(a, m, b, q, mid):
	p = q.copy()
	arr = a.copy()
	s = 0
	for i in range(len(arr)):
		arr[i] = (arr[i] + mid) % m
		if p[arr[i]] == 0:
			return 0
		p[arr[i]] = p[arr[i]] - 1
	return 1

def ans(a, l1, l2):
	if a >= l1 and a <= l2:
		z1 = 0
	elif a < l1:
		z1 = l1 - a
	else:
		z1 = a - l2
	return z1
for _ in range(inp()):
	(a, b, c, r) = line()
	p = [a, b]
	p.sort()
	a = p[0]
	b = p[1]
	l1 = c - r
	l2 = c + r
	if (a < l2 and a < l1) and (b < l2 and b < l1) or ((a > l1 and a > l2) and (b > l1 and b > l2)):
		print(b - a)
	else:
		print(ans(a, l1, l2) + ans(b, l1, l2))


t = int(input())
while t:
	(a, b, c, r) = map(int, input().split())
	e = min(a, b)
	f = max(a, b)
	total = f - e
	cov1 = c - r
	cov2 = c + r
	ans1 = cov1 - e
	ans2 = f - cov2
	if ans1 < 0:
		ans1 = 0
	if ans2 < 0:
		ans2 = 0
	print(min(total, ans1 + ans2))
	t -= 1


import math
t = int(input())
for cnt in range(t):
	(a, b, c, r) = map(int, input().split())
	(b, a) = (max(a, b), min(a, b))
	if c - r >= b or c + r <= a:
		print(b - a)
	else:
		print(b - a - (min(c + r, b) - max(a, c - r)))


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	(a1, b1) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	print(b - a - (max(min(b, b1), a) - min(max(a, a1), b)))


q = int(input())
for _ in range(q):
	(a, b, c, r) = map(int, input().split(' '))
	x = 0
	if a > b:
		x = a
		a = b
		b = x
	x = b - a
	if c - r <= a:
		if c + r >= b:
			x = 0
		elif c + r > a:
			x = b - (c + r)
	elif c - r < b:
		if c + r >= b:
			x = c - r - a
		else:
			x = x - 2 * r
	print(x)


n = int(input())
res = []
for i in range(0, n):
	arr = list(map(int, input().split()))
	(a, b, tower, coverage) = (arr[0], arr[1], arr[2], arr[3])
	lo = a if a <= b else b
	hi = b if a <= b else a
	lo_tower = tower - coverage
	hi_tower = tower + coverage
	outside = hi - lo
	if lo_tower >= lo and hi_tower <= hi:
		outside -= hi_tower - lo_tower
	elif hi_tower >= lo and lo_tower <= lo:
		outside -= hi_tower - lo
	elif lo_tower <= hi and hi_tower >= hi:
		outside -= hi - lo_tower
	if outside < 0:
		outside = 0
	res.append(outside)
for i in range(0, len(res)):
	print(res[i])


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
t = intput()
for _ in range(t):
	(a, b, c, r) = intsput()
	lowbound = c - r
	highbound = c + r
	if a > b:
		(a, b) = (b, a)
	rl = max(a, lowbound)
	rh = min(b, highbound)
	if rh > rl:
		print(b - a - rh + rl)
	else:
		print(b - a)


N = int(input())
for i in range(N):
	(a, b, c, r) = map(int, input().split())
	upper = c + r
	lower = c - r
	start = min(a, b)
	end = max(a, b)
	result = end - start
	if r != 0 and upper >= start and (lower <= end):
		result = max(0, lower - start) + max(0, end - upper)
	print(result)


for tcase in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(ca, cb) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	if b <= ca:
		print(b - a)
	elif cb <= a:
		print(b - a)
	elif a <= ca <= b <= cb:
		print(ca - a)
	elif ca <= a <= cb <= b:
		print(b - cb)
	elif a <= ca <= cb <= b:
		print(ca - a + (b - cb))
	elif ca <= a <= b <= cb:
		print(0)
	else:
		print(0)


tests = int(input())
for te in range(tests):
	(a, b, c, r) = list(map(int, input().split()))
	d = c + r
	c = c - r
	answer = 0
	if a > b:
		(a, b) = (b, a)
	if d < a or c > b:
		print(b - a)
	elif d >= a and d <= b:
		if c < a:
			print(b - a - (d - a))
		elif c >= a:
			print(b - a - (d - c))
	elif d > b:
		if c < a:
			print(0)
		elif c >= a and c <= d:
			print(b - a - (b - c))


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(c, d) = (c - d, c + d)
	if d <= a or b <= c:
		print(b - a)
	else:
		print(max(0, c - a) + max(0, b - d))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	if c - r <= a <= c + r:
		print(b - min(b, r + c))
	elif c - r <= b <= c + r:
		print(min(b, c - r) - a)
	elif a <= c - r <= c + r <= b:
		print(b - a - 2 * r)
	else:
		print(b - a)


res = []
t = int(input())
for ind in range(0, t):
	inps = input().split()
	a = int(inps[0])
	b = int(inps[1])
	c = int(inps[2])
	r = int(inps[3])
	s = 0
	if b < a:
		temp = a
		a = b
		b = temp
	if c + r < a:
		s = b - a
	elif c - r > b:
		s = b - a
	elif c - r >= a and c + r <= b:
		s = b - a - (c + r - (c - r))
	elif c - r >= a and c + r >= b:
		s = c - r - a
	elif c - r <= a and c + r <= b:
		s = b - (c + r)
	elif c - r <= a and c + r >= b:
		s = 0
	res.append(s)
for x in res:
	print(x)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	x = min(a, b)
	y = max(a, b)
	z = min(y, c + r)
	w = max(x, c - r)
	if c + r < x or c - r > y:
		print(y - x)
	else:
		print(y - x - (z - w))


t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	c = int(l[2])
	r = int(l[3])
	l1 = min(a, b)
	l2 = min(c - r, c + r)
	r1 = max(a, b)
	r2 = max(c - r, c + r)
	L = max(l1, l2)
	R = min(r1, r2)
	if L >= R:
		cov = 0
	else:
		cov = R - L
	print(r1 - l1 - cov)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if c <= a <= b:
		ans = max(0, abs(a - b) - max(0, r - abs(c - a)))
	elif c <= b <= a:
		ans = max(0, abs(a - b) - max(0, r - abs(c - b)))
	elif a <= b <= c:
		ans = max(0, abs(a - b) - max(0, r - abs(c - b)))
	elif b <= a <= c:
		ans = max(0, abs(a - b) - max(0, r - abs(c - a)))
	else:
		ans = max(0, abs(c - a) - r) + max(0, abs(c - b) - r)
	print(ans)


m = []
x = []
t = int(input())
for i in range(t):
	m.append(list(map(int, input().split())))
for i in range(t):
	x = m[i]
	a = x[0]
	b = x[1]
	c = x[2]
	r = x[3]
	L = max(min(a, b), c - r)
	R = min(max(a, b), c + r)
	print(abs(a - b) - max(0, R - L))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().strip().split())
	(a, b) = (min(a, b), max(a, b))
	left = c - r
	right = c + r
	s = 0
	if left >= b or right <= a:
		print(b - a)
	else:
		print(max(0, c - r - min(a, b)) + max(0, max(a, b) - (c + r)))


test_cases = int(input())
for _ in range(test_cases):
	(a, b, c, r) = map(int, input().split())
	total_time = max(b, a) - min(b, a)
	coverage_time = min(c + r, max(a, b)) - max(min(b, a), c - r)
	print(total_time - max(0, coverage_time))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if max(a, b) == a:
		tb = b
		b = a
		a = tb
	rl = [c - r, c + r]
	res = 0
	if rl[1] <= b and rl[0] <= b and (rl[1] >= a) and (rl[0] >= a):
		res = b - a - abs(b - (c + r) - (b - (c - r)))
	elif rl[1] <= a and rl[0] <= a or (rl[1] >= b and rl[0] >= b):
		res = b - a
	elif rl[1] > b and rl[0] < b:
		res = rl[0] - a
	elif rl[1] > a and rl[0] < a:
		res = b - rl[1]
	else:
		res = 0
	if res < 0:
		print(0)
	else:
		print(res)


t = int(input())
for i in range(t):
	points_in = input()
	points = points_in.split()
	points = list(map(int, points))
	if points[0] > points[1]:
		(points[0], points[1]) = (points[1], points[0])
	a = points[0]
	b = points[1]
	c = points[2]
	r = points[3]
	left = c - r - a
	right = b - (c + r)
	if left < 0:
		left = 0
	elif right < 0:
		right = 0
	if c + r < a or c - r > b:
		res = b - a
	else:
		res = left + right
	if res < 0:
		res = 0
	print(res)


for _ in range(int(input())):
	(a, b, c, r) = [int(i) for i in input().split()]
	if a > b:
		(a, b) = (b, a)
	print(b - a - (max(min(c + r, b), a) - min(max(a, c - r), b)))


ans = []
t = int(input())
for tc in range(t):
	(a, b, c, r) = map(int, input().split())
	cs = c - r
	ce = c + r
	if a > b:
		tmp = a
		a = b
		b = tmp
	if ce < a or cs > b:
		print(b - a)
	else:
		print(max(0, cs - a) + max(0, b - ce))


from collections import Counter, deque, defaultdict, OrderedDict, namedtuple
from bisect import bisect_left, bisect_right, insort
from math import sqrt, ceil, floor, factorial, gcd
from sys import stdin
t = int(stdin.readline())
while t:
	(a, b, c, r) = map(int, stdin.readline().split())
	if a > b:
		(a, b) = (b, a)
	if c > b:
		if c - r <= a:
			ans = 0
		else:
			ans = min(b, c - r) - a
	elif c < a:
		if c + r >= b:
			ans = 0
		else:
			ans = min(b - a + 1, b - max(a, c + r))
	else:
		right = b - min(b, c + r)
		left = max(0, c - r - a)
		ans = left + right
	print(ans)
	t -= 1


for t in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	d = b - a
	if c + r <= a or c - r >= b:
		print(d)
	elif c - r < a:
		print(max(0, b - c - r))
	elif c + r > b:
		print(max(0, c - r - a))
	else:
		print(max(0, d - 2 * r))


for _ in range(int(input())):
	(A, B, c, r) = map(int, input().split())
	a = min(A, B)
	b = max(A, B)
	m = c - r
	n = c + r
	ans = 0
	if n < a:
		ans = b - a
	elif m > b:
		ans = b - a
	elif m <= a and n >= b:
		ans = 0
	elif m >= a and n <= b:
		ans = b - a - 2 * r
	elif m >= a and n >= b:
		ans = b - a - (b - m)
	elif m <= a and n <= b:
		ans = b - a - (n - a)
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	cl = c - r
	cr = c + r
	if a < b:
		pl = a
		pr = b
	else:
		pl = b
		pr = a
	if cr >= pl and cl <= pr:
		if cl < pl:
			u = 0
		else:
			u = cl - pl
		if cr > pr:
			v = 0
		else:
			v = pr - cr
		tt = v + u
	else:
		tt = pr - pl
	print(tt)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	if c - r > x or c + r < y:
		print(x - y)
	elif c - r >= y and c + r <= x:
		print(x - y - 2 * r)
	elif c - r < y and c + r > x:
		print(0)
	elif c - r < y and c + r >= y:
		print(x - c - r)
	elif c - r <= x and c + r > x:
		print(c - r - y)


n = int(input())
ans = []
for i in range(n):
	(a, b, c, r) = input().split(' ')
	(a, b, c, r) = (int(a), int(b), int(c), int(r))
	(cell_l, cell_r) = (c - r, c + r)
	(L, R) = (min(a, b), max(a, b))
	if R < cell_l or L > cell_r:
		ans.append(R - L)
	else:
		ans.append(max(R - cell_r, 0) - min(L - cell_l, 0))
for i in ans:
	print(i)


test = int(input())
for i in range(test):
	(a, b, c, r) = map(int, input().split())
	(a, b, c) = (0, max(a, b) - min(a, b), c - min(a, b))
	x = c - r
	y = c + r
	if x < 1:
		if y < 1:
			print(b)
		elif y >= b:
			print(0)
		else:
			print(b - y)
	elif x >= b:
		print(b)
	else:
		t = x
		if y < b:
			t += b - y
		print(t)


t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(i) for i in input().split()]
	(a, b) = (min(a, b), max(a, b))
	t = b - a
	if c < a:
		t -= max(0, min(c + r - a, b - a))
	elif b < c:
		t -= max(0, min(b - (c - r), b - a))
	else:
		t -= max(0, min(b - c, r))
		t -= max(0, min(c - a, r))
	print(t)


def getTime(a, b, c, r):
	if a > b:
		(a, b) = (b, a)
	if c <= a:
		if r < a - c:
			return b - a
		elif r >= a - c and r <= b - c:
			return b - c - r
		else:
			return 0
	elif c < b:
		return max(c - r - a, 0) + max(b - c - r, 0)
	elif c - r >= b:
		return b - a
	elif c - r < b and c - r > a:
		return c - r - a
	else:
		return 0
number = int(input())
for i in range(0, number):
	numbers = input()
	numberlist = numbers.split()
	numberss = list(map(int, numberlist))
	print(getTime(numberss[0], numberss[1], numberss[2], numberss[3]))


def solve():
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	st = max(c - r, a)
	ed = min(c + r, b)
	ans = b - a - max(0, ed - st)
	print(ans)
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if b <= c - r or c + r <= a:
		print(b - a)
	elif c - r <= b <= c + r:
		print(max(c - r - a, 0))
	elif c - r <= a <= c + r:
		print(max(b - (c + r), 0))
	elif a < c - r and b > c + r:
		print(b - (c + r) + c - r - a)


def f(A, B, c, d):
	(a, b) = sorted([A, B])
	(x, y) = sorted([c - d, c + d])
	if a <= b <= x <= y:
		return b - a
	elif a <= x <= b <= y:
		return x - a
	elif a <= x <= y <= b:
		return b - a - (y - x)
	elif x <= a <= b <= y:
		return 0
	elif x <= a <= y <= b:
		return b - y
	elif x <= y <= a <= b:
		return b - a
n = int(input())
a = []
for i in range(n):
	a.append(f(*[int(j) for j in input().split()]))
for i in a:
	print(i)


casos = input()
for i in range(int(casos)):
	(a, b, c, r) = [int(x) for x in input().split(' ')]
	l = min(a, b)
	d = max(a, b)
	corr = abs(min(a, b, c))
	if corr < 0:
		a += corr
		b += corr
		c += corr
	if c > d:
		a1 = d - l - (d - (c - r)) if d - l - (d - (c - r)) > 0 else 0
		a2 = 0
	elif c < l:
		a2 = d - l - (c + r - l) if d - l - (c + r - l) > 0 else 0
		a1 = 0
	else:
		a1 = c - r - l if c - r - l > 0 else 0
		a2 = d - r - c if d - r - c > 0 else 0
	rta = min(a1, d - l) + min(a2, d - l)
	print(rta)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	c1 = c - r
	c2 = c + r
	if a > b:
		(a, b) = (b, a)
	if a < c1 and b < c1 or (a > c2 and b > c2):
		print(b - a)
		continue
	ans = 0
	if a < c1:
		ans += c1 - a
	if c2 < b:
		ans += b - c2
	print(ans)


t = int(input())
for i in range(t):
	s = input().split()
	a = min([int(s[0]), int(s[1])])
	b = max([int(s[0]), int(s[1])])
	c = int(s[2])
	r = int(s[3])
	uplim = c + r
	downlim = c - r
	if downlim <= a and uplim <= a:
		s = b - a
	elif downlim >= b and uplim >= b:
		s = b - a
	elif downlim >= a and uplim <= b:
		s = downlim - a + (b - uplim)
	elif downlim <= a and uplim < b and (uplim >= a):
		s = b - uplim
	elif downlim > a and downlim <= b and (uplim >= b):
		s = downlim - a
	else:
		s = 0
	print(s)


t = int(input())
ans = [0] * t
for i in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	if c <= a:
		if c + r <= a:
			ans[i] = b - a
		elif c + r <= b:
			ans[i] += b - c - r
	elif c <= b:
		if c - r > a:
			ans[i] += c - r - a
		if c + r < b:
			ans[i] += b - c - r
	elif c - r >= b:
		ans[i] = b - a
	elif c - r >= a:
		ans[i] = c - r - a
for item in ans:
	print(item)


for t in range(int(input())):
	(a, b, l, r) = map(int, input().split())
	i = min(a, b)
	e = max(a, b)
	c = 0
	if l <= i:
		c = max(0, e - max(i, l + r))
	elif l >= e:
		c = max(0, min(l - r, e) - i)
	else:
		c = max(0, l - r - i) + max(0, e - (l + r))
	print(c)


for i in range(int(input())):
	(w, x, y, z) = map(int, input().split())
	a = max(w, x)
	w = min(w, x)
	x = a
	n = y - z
	m = y + z
	if n <= w and x <= m or (n >= w and x >= m):
		print(max(0, abs(x - w) - 2 * z))
	elif n <= x and m > x:
		print(abs(x - w) - (x - n))
	elif max(n, m) < w or min(n, m) > x:
		print(abs(w - x))
	else:
		print(abs(x - w) - (m - w))


def inp(n):
	if n == 1:
		return map(int, stdin.readline().split())
	elif n == 2:
		return map(float, stdin.readline().split())
	else:
		return map(str, stdin.readline().split())
from sys import *
for i in range(int(input())):
	(a, b, c, r) = inp(1)
	(mi, ma) = (min(a, b), max(a, b))
	(l, u, ans) = (c - r, c + r, ma - mi)
	if l <= ma and l >= mi:
		if u >= ma:
			ans -= ma - l
		else:
			ans -= u - l
	elif u <= ma and u >= mi:
		if l >= mi:
			ans -= u - l
		else:
			ans -= u - mi
	elif l <= mi and u >= ma:
		ans = 0
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	(a, b, c, r) = map(int, input().split())
	if a > b:
		a ^= b
		b ^= a
		a ^= b
	if c - r <= a and c + r >= b:
		print('0')
		continue
	if a <= c - r and b >= c + r:
		print(b - a - 2 * r)
		continue
	if c - r > b or c + r < a:
		print(b - a)
		continue
	if b >= c + r:
		print(b - c - r)
		continue
	else:
		print(c - r - a)
		continue


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	u = c + r
	d = c - r
	if max(a, b) != b:
		(a, b) = (b, a)
	if u < a:
		print(b - a)
	elif d > b:
		print(b - a)
	elif u >= b and d <= a:
		print(0)
	elif d >= a and u >= b:
		print(d - a)
	elif u <= b and d <= a:
		print(b - u)
	else:
		print(b - a - (u - d))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		temp = a
		a = b
		b = temp
	min_coverage = max(a, c - r)
	max_coverage = min(b, c + r)
	if c + r < a:
		min_coverage = 0
		max_coverage = 0
	if c - r > b:
		min_coverage = 0
		max_coverage = 0
	print(b - a - (max_coverage - min_coverage))


t = int(input())
while t:
	t -= 1
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	lb = c - r
	rb = c + r
	if lb < a and rb < a or (lb > b and rb > b):
		print(b - a)
		continue
	lb = max(a, lb)
	rb = min(b, rb)
	diff = abs(rb - lb)
	ans = b - a - diff
	print(max(0, ans))


import sys
import collections
import heapq
import math
import bisect
input = sys.stdin.readline

def rints():
	return map(int, input().strip().split())

def rstr():
	return input().strip()

def rint():
	return int(input().strip())

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = rint()
for _ in range(t):
	(a, b, c, r) = rints()
	if a > b:
		(a, b) = (b, a)
	total = abs(a - b)
	left = c - r
	right = c + r
	if left <= a and right >= b:
		print(0)
	elif left >= a and right <= b:
		print(total - abs(left - right))
	elif left <= a and right >= a and (right < b):
		print(total - abs(right - a))
	elif left > a and left <= b and (right >= b):
		print(total - abs(left - b))
	else:
		print(total)


inp = input
for _ in range(int(inp().strip())):
	(a, b, c, r) = map(int, inp().strip().split(' '))
	_a = a
	_b = b
	a = min(_a, _b)
	b = max(_a, _b)
	c1 = c - r
	c2 = c + r
	if c1 <= a and c2 >= b:
		print(0)
	elif c1 <= a and c2 <= a or (c1 >= b and c2 >= b):
		print(b - a)
	elif c1 <= a:
		print(b - c2)
	elif c2 >= b:
		print(c1 - a)
	else:
		print(c1 - a + (b - c2))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split(' '))
	m = c - r
	n = c + r
	if a > b:
		temp = a
		a = b
		b = temp
	if a <= m:
		if b >= n:
			print(b - n + m - a)
		elif b < n and b >= m:
			print(m - a)
		elif b <= m and b < n:
			print(b - a)
	elif a >= n:
		print(b - a)
	elif a < n and b >= n:
		print(b - n)
	elif b < n:
		print(0)


t = int(input())
for i in range(0, t):
	(a, b, c, r) = [int(x) for x in input().split()]
	(a, b) = (min(a, b), max(a, b))
	start = c - r
	end = c + r
	if start >= a and end <= b:
		region = b - a - 2 * r
	elif end <= a:
		region = b - a
	elif start >= b:
		region = b - a
	else:
		st = max(start, a)
		ed = min(end, b)
		region = b - a - (ed - st)
	print(region)


t = int(input())
while t > 0:
	(a1, b1, c, r) = [int(x) for x in input().split()]
	a = min(a1, b1)
	b = max(a1, b1)
	r1 = 0
	if c > a and c < b:
		z = c - r - a
		z1 = b - (c + r)
		if z1 > 0:
			r1 += z1
		if z > 0:
			r1 += z
	if c < a:
		z = c + r - a
		if z > 0:
			r1 = b - a - z
		else:
			r1 = b - a
	if c > b:
		z = b - (c - r)
		if z > 0:
			r1 = b - a - z
		else:
			r1 = b - a
	if c == a:
		z = b - (c + r)
		if z > 0:
			r1 = z
	if c == b:
		z = c - r - a
		if z > 0:
			r1 = z
	if r1 < 0:
		r1 = 0
	print(r1)
	t = t - 1


from sys import stdin, stdout
n = int(stdin.readline().strip())
for i in range(n):
	(l, t, b, r) = map(int, stdin.readline().strip().split())
	if l > t:
		f = t
		t = l
		l = f
	x = max(min(b - r, t) - l, 0)
	x += max(0, t - max(b + r, l))
	print(x)


def solve():
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(L, R) = (max(a, c - r), min(b, c + r))
	return b - a - max(0, R - L)

def main():
	t = int(input())
	for _ in range(t):
		print(solve())
main()


t = int(input())
for i in range(t):
	(p1, p2, c, r) = map(int, input().split())
	p3 = c - r
	p4 = c + r
	if p1 > p2:
		sas = p1
		p1 = p2
		p2 = sas
	print(abs(p1 - p2) - max(min(p2, p4) - max(p1, p3), 0))


def main():
	for _ in range(int(input())):
		(a, b, c, r) = list(map(int, input().split()))
		(a, b) = (min(a, b), max(a, b))
		l = min(c - r, b)
		u = max(a, c + r)
		print(max(l, a) - a + b - min(u, b))
main()


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	(a, b, c, r) = list(map(int, stdin.readline().split()))
	if a > b:
		(a, b) = (b, a)
	l = c - r
	r = c + r
	if r <= a or l >= b:
		print(b - a)
		continue
	if l <= a:
		if r >= b:
			print(0)
		else:
			print(b - r)
	elif r >= b:
		print(l - a)
	else:
		print(l - a + b - r)


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	coverage1 = c - d
	coverage2 = c + d
	if a > b:
		(a, b) = (b, a)
	if coverage1 > b:
		print(b - a)
	elif coverage2 < a:
		print(b - a)
	else:
		if coverage1 < a:
			coverage1 = a
		if coverage2 > b:
			coverage2 = b
		print(b - a - abs(coverage2 - coverage1))


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


for i in range(int(input())):
	(x, y, z, a) = [int(i) for i in input().split()]
	if x > y:
		(x, y) = (y, x)
	b = z - a - x
	if b < 0:
		b = 0
	c = y - z - a
	if c < 0:
		c = 0
	if z + a < x or z - a > y:
		print(y - x)
	else:
		print(b + c)


from sys import stdin, stdout
read = lambda : map(int, stdin.readline().split())
I = lambda : stdin.readline()
for _ in range(int(I())):
	(a, b, c, r) = read()
	(a, b) = sorted([a, b])
	print(b - a - max(0, min(b, c + r) - max(a, c - r)))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if abs(a - b) == 0:
		print(0)
	else:
		x = min(a, b)
		y = max(a, b)
		z1 = c + r
		z2 = c - r
		if z2 <= x and z1 >= y:
			print(0)
		elif z2 >= x and z2 <= y and (z1 >= y):
			print(z2 - x)
		elif z1 >= x and z1 <= y and (z2 <= x):
			print(y - z1)
		elif z1 >= x and z1 <= y and (z2 <= y) and (z2 >= x):
			print(y - x - (z1 - z2))
		else:
			print(y - x)


for tc in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	x = c - r
	y = c + r
	ove = max(0, min(b, y) - max(a, x))
	print(b - a - ove)


t = int(input())
result = []
for i in range(0, t):
	inp = input()
	inp = inp.split()
	inp = list(map(lambda x: int(x), inp))
	a = inp[0]
	b = inp[1]
	c = inp[2]
	r = inp[3]
	if a > b:
		(a, b) = (b, a)
	result.append(0)
	if a < c - r:
		if b < c - r:
			result[i] = b - a
		else:
			result[i] += c - r - a
	if b > c + r:
		if a > c + r:
			result[i] = b - a
		else:
			result[i] += b - (c + r)
for i in range(0, t):
	print('%d' % result[i])


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(a, b, c, r) = inp()
	if a > b:
		(a, b) = (b, a)
	st = c - r
	end = c + r
	if st > end:
		(st, end) = (end, st)
	if a < st:
		if b <= st:
			ans = b - a
		elif b > st and b <= end:
			ans = st - a
		else:
			ans = st - a + (b - end)
	elif a >= st and a < end:
		if b <= end:
			ans = 0
		else:
			ans = b - end
	else:
		ans = b - a
	out(ans)


v = int(input())
r = []
for i in range(v):
	(fr, to, st, rd) = list(map(int, input().split()))
	if fr > to:
		(fr, to) = (to, fr)
	r.append(to - fr - max(min(to, st + rd) - max(fr, st - rd), 0))
for i in range(v):
	print(r[i])


n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	left = c - r
	right = c + r
	ch = b - a + 1
	if left > b or right < a:
		print(ch - 1)
	elif left < a and right > b:
		print(0)
	elif a <= left <= b and right >= b:
		print(ch - (b - left + 1))
	elif left <= a and a <= right <= b:
		print(ch - (right - a + 1))
	else:
		print(ch - (right - left + 1))


t = int(input())
s = []
for kgg in range(0, t):
	x = input()
	xx = x.split()
	pp = [int(xx[0]), int(xx[1])]
	pp.sort()
	a = pp[0]
	b = pp[1]
	c = int(xx[2])
	r = int(xx[3])
	if r == 0:
		s.append(b - a)
	elif c < a:
		if c + r <= a:
			s.append(b - a)
		elif a < c + r <= b:
			s.append(b - c - r)
		else:
			s.append(0)
	elif a <= c <= b:
		g = 0
		if a <= c - r:
			g += r
		elif a > c - r:
			g = g + (c - a)
		if c + r <= b:
			g += r
		elif b < c + r:
			g = g + (b - c)
		s.append(b - a - g)
	elif b <= c - r:
		s.append(b - a)
	elif c - a - r >= 0:
		s.append(c - a - r)
	else:
		s.append(0)
for i in s:
	print(i)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	(a, b, c, r) = get_int_list()
	(a, b) = (min(a, b), max(a, b))
	dist = b - a
	(left, right) = (c - r, c + r)
	avail = max(0, min(right, b) - max(left, a))
	print(dist - avail)


n = int(input())
while n > 0:
	(a, b, c, d) = map(int, input().split())
	if a > b:
		s = b
		e = a
	else:
		s = a
		e = b
	x1 = c - d
	x2 = c + d
	if x1 < s and x2 <= s:
		r = e - s
	elif x1 >= s and x2 <= e:
		r = e - s - (x2 - x1)
	elif x1 < s and x2 > e:
		r = 0
	elif x1 < s and x2 > s and (x2 <= e):
		r = e - s - (x2 - s)
	elif x1 >= s and x1 < e and (x2 > e):
		r = e - s - (e - x1)
	elif x1 >= e and x2 > e:
		r = e - s
	print(r)
	n -= 1


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	su = a + b
	a = min(a, b)
	b = su - a
	if c < a:
		if c + r < a:
			print(abs(b - a))
			continue
		elif c + r >= a and c + r < b:
			sp = c + r
			ep = b
			print(abs(sp - ep))
			continue
		else:
			print('0')
			continue
	elif c > b:
		if c - r >= b:
			print(abs(b - a))
			continue
		elif c - r <= a:
			print('0')
			continue
		else:
			sp = a
			ep = c - r
			print(abs(sp - ep))
			continue
	else:
		if c - r >= a:
			sp = c - r
		else:
			sp = a
		if c + r >= b:
			ep = b
		else:
			ep = c + r
	print(abs(b - a) - abs(sp - ep))


def main():
	t = int(input())
	for _ in range(t):
		(a, b, c, r) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		if a > c + r or b < c - r:
			print(b - a)
			continue
		lower = max(a, c - r)
		upper = min(b, c + r)
		covered = upper - lower
		print(b - a - covered)
main()


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	s1 = min(a, b)
	e1 = max(a, b)
	s = max(c - r, s1)
	e = min(c + r, e1)
	print(e1 - s1 - (e - s if e > s else 0))


from sys import stdin, exit
from math import *

def main():

	def len_intersect(a, b, c, d):
		if d <= a or c >= b:
			return 0
		(u, v) = (max(a, c), min(b, d))
		return max(0, v - u)
	for testcase in range(int(stdin.readline())):
		(a, b, c, r) = list(map(int, stdin.readline().split()))
		if a > b:
			(a, b) = (b, a)
		print(b - a - len_intersect(a, b, c - r, c + r))

def __starting_point():
	main()
__starting_point()


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	l = c - r
	r = c + r
	if b <= r and a >= l:
		print(0)
	elif b <= r and a < l:
		if b <= l:
			print(abs(a - b))
		else:
			print(abs(a - l))
	elif b >= r and a <= l:
		print(abs(a - l) + abs(b - r))
	elif l <= a and b >= r:
		if a <= r:
			print(abs(b - r))
		else:
			print(abs(b - a))


def main():
	t = int(input())
	for i in range(t):
		(a, b, c, r) = map(int, input().split())
		(a, b) = (min(a, b), max(a, b))
		now1 = c - r
		now2 = c + r
		per = 0
		if c + r <= a or c - r >= b:
			per = 0
		else:
			per = abs(max(a, c - r) - min(b, c + r))
		print(abs(a - b) - per)
main()


t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	(a, b) = (min(a, b), max(a, b))
	res = b - a - (max(min(b, c + r), a) - min(max(a, c - r), b))
	print(res)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	L = c - r
	R = c + r
	st = int(max(L, min(a, b)))
	end = int(min(R, max(a, b)))
	ans = abs(b - a) - max(0, end - st)
	print(ans)


for _ in [0] * int(input()):
	(*a, c, r) = map(int, input().split())
	(a, b) = sorted(a)
	print(b - a - max(0, min(b, c + r) - max(a, c - r)))


import sys, math
MOD = 10 ** 9 + 7
for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if c + r <= a or b <= c - r:
		ans = b - a
	else:
		ans = b - min(b, c + r) + max(a, c - r) - a
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	s = max(min(a, b), c - r)
	f = min(max(a, b), c + r)
	l = max(0, f - s)
	print(abs(a - b) - l)


t = int(input())
for q in range(t):
	(a, b, c, r) = map(int, input().split())
	x = c - r
	y = c + r
	ans = 0
	f = 0
	if a > b:
		if b <= x <= a or b <= y <= a:
			if b <= x <= a:
				ans += x - b
			if b <= y <= a:
				ans += a - y
		elif x < a < y and x < b < y:
			ans = 0
		else:
			ans += a - b
	elif a <= x <= b or a <= y <= b:
		if a <= x <= b:
			ans += x - a
		if a <= y <= b:
			ans += b - y
	elif x < a < y and x < b < y:
		ans = 0
	else:
		ans = b - a
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	e = c - r
	f = c + r
	g = min(a, b)
	h = max(a, b)
	if g >= f:
		print(h - g)
	elif h <= e:
		print(h - g)
	elif g >= e and h <= f:
		print(0)
	elif g < e and h > f:
		print(h - g - 2 * r)
	elif g < e:
		if a > e:
			print(abs(b - e))
		else:
			print(abs(e - a))
	elif a < f:
		print(abs(f - b))
	else:
		print(abs(f - a))


n = int(input())
for t in range(n):
	a = [int(x) for x in input().split()]
	if a[0] > a[1]:
		(a[0], a[1]) = (a[1], a[0])
	k = 0
	if a[2] - a[3] >= a[1] or a[2] + a[3] <= a[0]:
		k = a[1] - a[0]
		print(k)
		continue
	if a[1] > a[2] + a[3]:
		k += a[1] - (a[2] + a[3])
	if a[0] < a[2] - a[3]:
		k += a[2] - a[3] - a[0]
	print(k)


for _ in range(int(input())):
	(a, b, c, r) = [int(x) for x in input().split(' ')]
	(from_pos, to_pos) = (min(a, b), max(a, b))
	res = 0
	if from_pos < c - r and to_pos > c - r:
		res += c - r - from_pos
	if to_pos > c + r and from_pos < c + r:
		res += to_pos - c - r
	if to_pos <= c - r or from_pos >= c + r:
		res += from_pos - to_pos
	print(abs(res))


for _ in range(int(input())):
	(a, b, c, r) = [int(x) for x in input().split()]
	distance_traveled = abs(b - a)
	x = range(min(a, b), max(a, b))
	y = range(c - r, c + r)
	if not y:
		print(distance_traveled)
	elif not x:
		print(0)
	else:
		print(distance_traveled - len(range(max(x[0], y[0]), min(x[-1], y[-1]) + 1)))


import sys

def main():
	for tc in range(int(input())):
		(a, b, c, r) = get_ints()
		if a > b:
			(a, b) = (b, a)
		arr = [c - r, c + r]
		ans = 0
		if a > c + r:
			print(abs(b - a))
			continue
		if b < c - r:
			print(abs(b - a))
			continue
		if a < c - r:
			ans += abs(a - (c - r))
		if b > c + r:
			ans += abs(b - (c + r))
		print(ans)
get_array = lambda : list(map(int, sys.stdin.readline().split()))
get_ints = lambda : map(int, sys.stdin.readline().split())
input = lambda : sys.stdin.readline().strip()
main()


for t in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	mins = min(a, b)
	maxs = max(a, b)
	minr = c - r
	maxr = c + r
	to = maxs - mins
	if minr >= maxs or maxr <= mins:
		print(to)
	elif minr < maxs <= maxr:
		print(max(to - (maxs - minr), 0))
	elif minr <= mins < maxr:
		print(max(to - (maxr - mins), 0))
	else:
		print(to - 2 * r)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	start = c - r
	end = c + r
	s1 = min(a, b)
	s2 = max(a, b)
	td = s2 - s1
	if s2 <= start or s1 >= end:
		print(s2 - s1)
	elif s1 >= start and s2 <= end:
		print('0')
	elif s1 >= start:
		print(s2 - end)
	elif s2 <= end:
		print(start - s1)
	else:
		print(s2 - s1 - (end - start))


a = int(input())
for i in range(0, a):
	(a, b, c, r) = list(map(int, input().split()))
	arr = [a, b]
	arr.sort()
	a = arr[0]
	b = arr[1]
	a = 0
	b = arr[1] - arr[0]
	c = c - arr[0]
	ncl = c - r
	ncr = c + r
	p = min(b, max(0, ncl))
	q = max(0, b - max(0, ncr))
	print(p + q)


t = int(input())
while t:
	(a1, b1, c, r) = map(int, input().split())
	a = min(a1, b1) + 10000000000
	b = max(a1, b1) + 10000000000
	c = c + 10000000000
	if c + r >= b and c - r <= a:
		print(0)
	elif c + r <= b and c - r <= a and (c + r >= a):
		print(b - c - r)
	elif c + r >= b and c - r >= a and (c - r <= b):
		print(c - r - a)
	elif c + r <= b and c - r >= a:
		print(b - a - 2 * r)
	else:
		print(abs(b - a))
	t = t - 1


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = sorted([a, b])
	ans = b - a
	lo = max(c - r, a)
	hi = min(c + r, b)
	if lo <= hi:
		ans -= hi - lo
	print(ans)


for i in range(int(input())):
	(x, y, c, r) = map(int, input().split())
	a = min(x, y)
	b = max(x, y)
	if c - r <= a and c + r >= b:
		print(0)
		continue
	if c <= a:
		print(max(0, b - a - max(0, c + r - a)))
	elif a <= c <= b:
		left = c - r
		right = r + c
		if left <= a:
			dis1 = c - a
		else:
			dis1 = r
		if right <= b:
			dis2 = r
		else:
			dis2 = b - c
		print(max(0, b - a - dis1 - dis2))
	else:
		print(max(0, b - a - max(0, b - (c - r))))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a == b:
		print(0)
		continue
	if a > b:
		(a, b) = (b, a)
	b -= 1
	x = b - a + 1
	rr = min(c + r - 1, b)
	ll = max(c - r, a)
	x -= max(0, rr - ll + 1)
	print(x)
	t -= 1


t = int(input())
count = 0
for test in range(t):
	(a, b, c, r) = tuple([int(x) for x in input().split(' ')])
	if a > b:
		(a, b) = (b, a)
	if c + r <= a or b <= c - r:
		print(b - a)
	elif a <= c - r <= b <= c + r:
		print(c - r - a)
	elif c - r <= a <= c + r < b:
		print(b - c - r)
	elif c - r <= a <= b <= c + r:
		print(0)
	elif a <= c - r <= c + r <= b:
		print(c - r - a + (b - c - r))
	count += 1


t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	x = c - r
	y = c + r
	s = max(0, x - min(a, b)) + max(0, max(a, b) - y)
	print(min(s, abs(a - b)))


t = int(input())
for val in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	min_cov = c - r
	max_cov = c + r
	min_trav = min(a, b)
	max_trav = max(a, b)
	uncov = 0
	if not (max_cov < min_trav or min_cov > max_trav):
		if min_trav > min_cov:
			uncov = max(max_trav - max_cov, 0)
		elif max_trav < max_cov:
			uncov = min_cov - min_trav
		else:
			uncov = max_trav - min_trav - 2 * r
	else:
		uncov = max_trav - min_trav
	print(uncov)


k = int(input())
points = []
for i in range(k):
	points.append(list(map(int, input().split(' '))))
for i in range(k):
	rasst = 0
	p = points[i]
	r = p[3]
	cent = p[2]
	if p[0] < p[1]:
		left = p[0]
		right = p[1]
	else:
		left = p[1]
		right = p[0]
	if cent > left and cent < right:
		if cent + r > right:
			rasst = rasst + (right - cent)
		else:
			rasst = rasst + r
		if cent - r < left:
			rasst = rasst + (cent - left)
		else:
			rasst = rasst + r
	if cent <= left:
		if cent + r > right:
			rasst = rasst + (right - left)
		elif cent + r > left:
			rasst = rasst + (cent + r - left)
	if cent >= right:
		if cent - r < left:
			rasst = rasst + (right - left)
		elif cent - r < right:
			rasst = rasst + (r - (cent - right))
	print(right - left - rasst)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
for i in range(ii()):
	(a, b, c, r) = mi()
	if a > b:
		(a, b) = (b, a)
	t = b - a
	x = max(a, c - r)
	y = min(b, c + r)
	if x < y:
		t = t - y
		t += x
	print(t)


t = int(input())
for i in range(0, t):
	(a, b, c, r) = [int(x) for x in input().split()]
	if b < a:
		te = b
		b = a
		a = te
	k = b - a
	if c + r < a and c - r < a:
		print(k)
	elif c + r > b and c - r > b:
		print(k)
	elif c + r > b and c - r < a:
		print(0)
	else:
		k1 = b - c - r
		k2 = c - r - a
		if k1 < 0:
			k1 = 0
		if k2 < 0:
			k2 = 0
		print(k1 + k2)


t = int(input())
for i in range(t):
	(a, b, c, r) = (int(x) for x in input().split())
	left = max(min(a, b), c - r)
	right = min(max(a, b), c + r)
	print(max(a, b) - min(a, b) - max(0, right - left))


t = int(input())
for test in range(t):
	(a1, b1, c, r) = map(int, input().split())
	a = min(a1, b1)
	b = max(a1, b1)
	l = c - r
	h = c + r
	if l >= a and h <= b:
		print(b - a - (h - l))
	elif h < a and l < a or (l > b and h > b):
		print(b - a)
	elif l < a and (h >= a and h <= b):
		print(b - a - (h - a))
	elif (l <= b and l >= a) and h > b:
		print(b - a - (b - l))
	elif l <= a and h >= b:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c, r) = list(map(int, input().strip().split()))
	e = c - r
	f = c + r
	d = min(a, b)
	g = max(a, b)
	s = 0
	if d > f:
		print(g - d)
		continue
	if g < e:
		print(g - d)
		continue
	if e - d > 0:
		s = s + e - d
	if g - f > 0:
		s = s + g - f
	print(s)


T = int(input())
while T > 0:
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	x = c - r
	y = c + r
	sum = 0
	if b >= x and a <= x and (b >= y):
		sum += x - a
		sum += b - y
	elif b >= x and a <= x and (y >= b):
		sum += x - a
	elif x <= a and y >= a and (y <= b):
		sum += b - y
	elif y <= a or x >= b:
		sum += b - a
	print(sum)
	T -= 1


asfe = int(input())
for adsdr in range(asfe):
	(x, y, c, r) = map(int, input().split())
	a = min(x, y)
	b = max(x, y)
	if a == b:
		print(0)
	else:
		l = c - r
		r = c + r
		if l < b:
			if l <= a:
				if r >= b:
					print(0)
				elif r <= a:
					print(abs(b - a))
				else:
					x = c - l
					y = r - c
					print(abs(b - r))
			elif r <= b:
				print(abs(b - a - (r - l)))
			else:
				print(abs(b - a - (b - l)))
		else:
			print(abs(b - a))


try:
	while True:
		t = int(input())
		for i in range(t):
			(a, b, c, r) = map(int, input().split())
			radmin = c - r
			radmax = c + r
			if a == b:
				print('0')
			elif radmax > a and radmax > b and (radmin < a) and (radmin < b):
				print('0')
			elif a < b:
				if radmin > b or radmax < a:
					print(abs(a - b))
				elif radmin <= a and radmax <= b:
					print(abs(b - a - (radmax - a)))
				elif radmin >= a and radmax >= b:
					print(abs(b - a - (b - radmin)))
				else:
					print(abs(b - a - (radmax - radmin)))
			elif radmin > a or radmax < b:
				print(abs(a - b))
			elif radmin <= b and radmax <= a:
				print(abs(a - b - (radmax - b)))
			elif radmin >= b and radmax >= a:
				print(abs(a - b - (a - radmin)))
			else:
				print(abs(a - b - (radmax - radmin)))
except EOFError:
	pass


from sys import stdin

def main():
	input = lambda : stdin.readline()[:-1]
	T = int(input())
	for _ in [0] * T:
		(A, B, C, R) = map(int, input().split())
		(cl, cr) = (C - R, C + R)
		if A > B:
			(a, b) = (B, A)
		else:
			(a, b) = (A, B)
		if cl <= a <= cr <= b:
			dup = cr - a
		elif a <= cl <= cr <= b:
			dup = cr - cl
		elif a <= cl <= b <= cr:
			dup = b - cl
		elif cl <= a <= b <= cr:
			dup = b - a
		else:
			dup = 0
		print(b - a - dup)
main()


t = int(input())
while t:
	t -= 1
	(a, b, c, r) = [int(x) for x in input().split()]
	left = c - r
	right = c + r
	(a, b) = (min(a, b), max(a, b))
	le = max(left, a)
	ri = min(right, b)
	val = ri - le
	if val < 0:
		val = 0
	print(b - a - val)


t = int(input())
i = 0
while i < t:
	(a, b, c, r) = map(int, input().split())
	ans = 0
	if a > b:
		(a, b) = (b, a)
	d = max(a, c - r)
	e = min(b, c + r)
	if d - a > 0:
		ans = ans + d - a
	if b - e > 0:
		ans = ans + b - e
	if ans > b - a:
		print(b - a)
	else:
		print(ans)
	i = i + 1


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(t,) = I()
while t:
	t -= 1
	l = I()
	(a, b, c, r) = [i for i in l]
	(a, b) = sorted([a, b])
	m = c - r
	n = c + r
	left = max(0, min(b, c) - max(a, m))
	right = max(0, min(b, n) - max(a, c))
	print(b - a - left - right)


testcase = int(input())
for _ in range(testcase):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(ub, lb) = (c + d, c - d)
	print(max(0, min(lb - a, b - a)) + max(0, min(b - ub, b - a)))


n = int(input())
ans = []
for i in range(n):
	temp = 0
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(left, right) = (c - r, c + r)
	if a <= left <= b:
		temp += left - a
	if a <= right <= b:
		temp += b - right
	if right <= a or left >= b:
		temp = b - a
	ans.append(temp)
print(*ans, sep='\n')


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
nb_tests = RI()
for _ in [0] * nb_tests:
	(a, b, c, r) = RMI()
	(a, b) = (min(a, b), max(a, b))
	left = max(a, c - r)
	rite = min(b, c + r)
	print(b - a - max(0, rite - left))


N = int(input())
for i in range(N):
	(a, b, c, r) = map(int, input().split())
	left = min(a, b)
	right = max(a, b)
	leftr = max(left, c - r)
	rightr = min(right, c + r)
	print(min(leftr - left + (right - rightr), right - left))


t = int(input())
while t > 0:
	t -= 1
	(a, b, c, r) = list(map(int, input().split()))
	y = c + r
	x = c - r
	if a > b:
		(a, b) = (b, a)
	dis = b - a
	if r == 0 or y <= a or x >= b:
		print(dis)
	elif x >= a:
		if y <= b:
			print(dis - 2 * r)
		else:
			print(dis - (b - x))
	elif x < a:
		if y <= b:
			print(dis - (y - a))
		else:
			print(0)


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	if a <= c <= b:
		ans = b - a
		ans -= max(min(c - a, r), 0)
		ans -= max(min(b - c, r), 0)
	elif c < a:
		ans = b - a
		ans -= max(min(c + r - a, r), 0)
	else:
		ans = b - a
		ans -= max(min(b - (c - r), r), 0)
	print(max(ans, 0))


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	c1 = c - r
	c2 = c + r
	x = -1
	y = -1
	if c1 <= a and c2 >= b:
		print(0)
	elif c1 >= b or a >= c2:
		print(b - a)
	elif a <= c1 <= b and c2 >= b:
		print(c1 - a)
	elif a <= c1 <= b and a <= c2 <= b:
		print(c1 - a + b - c2)
	elif c1 <= a and a <= c2 <= b:
		print(b - c2)


t = int(input())
for i in range(t):
	(a, b, c, r) = input().strip().split(' ')
	(a, b, c, r) = [int(a), int(b), int(c), int(r)]
	ans = 0
	if c >= min(a, b) and c <= max(a, b):
		if c - r <= min(a, b) and c + r >= max(a, b):
			ans += abs(max(a, b) - min(a, b))
		elif c - r <= min(a, b):
			ans += abs(c + r - min(a, b))
		elif c + r >= max(a, b):
			ans += abs(c - r - max(a, b))
		else:
			ans += abs(2 * r)
		x = max(a, b) - min(a, b)
		print(x - ans)
	elif c < a:
		if c + r <= min(a, b):
			ans += 0
		elif c + r >= max(a, b):
			ans += abs(max(a, b) - min(a, b))
		else:
			ans += abs(c + r - min(a, b))
		x = abs(max(a, b) - min(a, b))
		print(x - ans)
	elif c > b:
		if c - r >= max(a, b):
			ans += 0
		elif c - r <= min(a, b):
			ans += abs(max(a, b) - min(a, b))
		else:
			ans += abs(max(a, b) - (c - r))
		x = abs(max(a, b) - min(a, b))
		print(x - ans)


for ii in range(int(input())):
	X = input().split()
	(a, b, c, r) = (min(int(X[0]), int(X[1])), max(int(X[0]), int(X[1])), int(X[2]), int(X[3]))
	(rA, rB) = (c - r, c + r)
	if a >= rA and b <= rB:
		print(0)
	elif a >= rA and b > rB:
		if a <= rB:
			print(b - rB)
		else:
			print(b - a)
	elif b <= rB and a < rA:
		if b >= rA:
			print(rA - a)
		else:
			print(b - a)
	else:
		print(rA - a + b - rB)


for _ in range(int(input())):
	(i, j, s, r) = map(int, input().split(' '))
	(i, j) = (min(i, j), max(i, j))
	if r == 0 or s + r <= i or s - r >= j:
		print(j - i)
		continue
	(s, r) = (s - r, s + r)
	print(max(s - i, 0) + max(j - r, 0))


def main():
	n = int(input())
	in_ls = []
	for i in range(n):
		tmp = map(int, input().split())
		in_ls.append(tmp)
	for idx in range(n):
		(a, b, c, r) = in_ls[idx]
		if a > b:
			(a, b) = (b, a)
		length = b - a
		if length == 0:
			print(0)
		elif r == 0:
			print(length)
		else:
			sl = c - r
			sr = c + r
			if sl <= a:
				if sr <= a:
					print(length)
				elif sr <= b:
					print(b - sr)
				else:
					print(0)
			elif sl < b:
				if sr < b:
					print(length - 2 * r)
				else:
					print(sl - a)
			else:
				print(length)
	return
main()


t = int(input())
A = []

def solve(a, b, c, d):
	(a, b) = (min(a, b), max(a, b))
	rc = c - d
	lc = c + d
	if rc >= b or lc <= a:
		A.append(b - a)
		return
	else:
		ans = max(0, rc - a) + max(0, b - lc)
		A.append(ans)
		return
for _ in range(t):
	(ta, tb, tc, td) = map(int, input().split())
	solve(ta, tb, tc, td)
for i in range(t):
	print(A[i])


import os
from io import BytesIO
for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	left = max(c - r, a)
	right = min(c + r, b)
	if right >= a and left <= right:
		print(b - a - (right - left))
	else:
		print(b - a)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b == a or (c - r <= a and c + r >= b):
		print(0)
	elif c - r <= a and a <= c + r:
		print(abs(b - (c + r)))
	elif c - r <= b and b <= c + r:
		print(abs(c - r - a))
	elif a > c + r or b < c - r:
		print(b - a)
	else:
		print(abs(c - r - a) + abs(b - (c + r)))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	d = abs(b - a)
	if c - r >= min(a, b) and c + r <= max(a, b):
		d -= 2 * r
		print(d)
		continue
	if c + r >= max(a, b):
		if c - r >= min(a, b) and c - r <= max(a, b):
			e = max(a, b) - (c - r)
			d -= e
			print(d)
			continue
		elif c - r > max(a, b):
			d -= 0
			print(d)
			continue
	if c - r <= max(a, b):
		if c + r <= max(a, b) and c + r >= min(a, b):
			e = c + r - min(a, b)
			d -= e
			print(d)
			continue
		elif c + r < max(a, b):
			d -= 0
			print(d)
			continue
	if c - r <= min(a, b) and c + r >= max(a, b):
		print(0)


n = int(input())
for i in range(n):
	(a, b, c, r) = (int(i) for i in input().split())
	if a > b:
		(a, b) = (b, a)
	all_way = b - a
	if c - r >= b or c + r <= a:
		print(all_way)
	elif c + r >= b:
		all_way = c - r - a
		if all_way <= 0:
			all_way = 0
		print(all_way)
	elif c - r <= a:
		all_way = b - (r + c)
		if all_way <= 0:
			all_way = 0
		print(all_way)
	else:
		all_way = c - r - a + (b - (c + r))
		print(all_way)


for _ in range(int(input())):
	(a, b, c, r) = [int(__) for __ in input().split()]
	(a, b) = (min(a, b), max(a, b))
	ans = 0
	if a < c - r:
		if b < c - r:
			ans += b - a
		else:
			ans += c - r - a
	if b > c + r:
		if a > c + r:
			ans += b - a
		else:
			ans += b - c - r
	print(ans)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(x, y) = (c - r, c + r)
	m1 = max(a, x)
	m2 = min(b, y)
	k = m2 - m1
	if m1 > m2:
		k = 0
	k = abs(k)
	print(abs(b - a) - k)


t = int(input())
while t != 0:
	(a, b, c, x) = map(int, input().strip().split())
	if a > b:
		temp = a
		a = b
		b = temp
	r = c - x
	l = c + x
	uncover = 0
	if r < a and l < a or (l > b and r > b):
		uncover = b - a
	elif r < a and l >= a:
		uncover = b - l
	elif r <= b and l > b:
		uncover = r - a
	elif r >= a and l <= b:
		uncover = r - a + (b - l)
	elif r <= a and l >= b:
		uncover = 0
	if uncover < 0:
		print(0)
	else:
		print(uncover)
	t -= 1


res = []
for t in range(int(input())):
	(a, b, c, r) = list(map(int, input().split(' ')))
	x = a
	a = min(a, b)
	b = max(x, b)
	left_cov = c - r
	right_cov = c + r
	if left_cov > b or right_cov < a:
		res.append(b - a)
	elif left_cov <= a and right_cov >= b:
		res.append(0)
	elif left_cov >= a and right_cov <= b:
		res.append(b - a - (right_cov - left_cov))
	elif left_cov >= a and right_cov >= b:
		res.append(left_cov - a)
	else:
		res.append(b - right_cov)
for x in res:
	print(x)


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	(r1, r2) = (c - r, c + r)
	time = 0
	if b >= a:
		if r1 >= b or r2 <= a:
			time = b - a
		elif r1 >= a and r2 <= b:
			time = b - a - (r2 - r1)
		elif r1 >= a and r1 < b and (r2 > b):
			time = b - a - (b - r1)
		elif r1 < a and r2 <= b and (r2 > a):
			time = b - a - (r2 - a)
		else:
			time = 0
	elif r1 >= a or r2 <= b:
		time = a - b
	elif r1 >= b and r2 <= a:
		time = a - b - (r2 - r1)
	elif r1 < b and r2 <= a and (r2 > b):
		time = a - b - (r2 - b)
	elif r1 >= b and r1 < a and (r2 > a):
		time = a - b - (a - r1)
	else:
		time = 0
	print(time)


n = int(input())
for i in range(n):
	s = input()
	l = s.split()
	for j in range(len(l)):
		l[j] = int(l[j])
	a = l[0]
	b = l[1]
	r = l[3]
	c1 = l[2] - r
	c2 = l[2] + r
	L = min(a, b)
	R = max(a, b)
	Cs = abs(max(c1, L) - min(c2, R))
	if c2 < L or c1 > R:
		Cs = 0
	t = R - L - Cs
	print(t)


for nt in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	ran = [c - r, c + r]
	ans = abs(b - a)
	if a >= c - r and a <= c + r:
		x = 1
	else:
		x = 0
	if b >= c - r and b <= c + r:
		y = 1
	else:
		y = 0
	if x == 1 and y == 1:
		print(0)
	elif x == 1 and y == 0:
		if b <= ran[0]:
			print(abs(b - ran[0]))
		else:
			print(abs(b - ran[-1]))
	elif x == 0 and y == 1:
		if a <= ran[0]:
			print(abs(a - ran[0]))
		else:
			print(abs(a - ran[-1]))
	elif a <= ran[0] and b <= ran[0]:
		print(abs(b - a))
	elif a >= ran[-1] and b >= ran[-1]:
		print(abs(b - a))
	else:
		print(abs(b - a) - 2 * r)


t = int(input())
while t > 0:
	t -= 1
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	print(min(max(c - r - a, 0) + max(b - (c + r), 0), abs(b - a)))


def solve(a, b, c, r):
	lb = min(a, b)
	rb = max(a, b)
	if c + r <= lb or rb <= c - r:
		ans = rb - lb
	elif c - r >= lb and c + r <= rb:
		ans = rb - lb - 2 * r
	elif c - r <= lb and c + r <= rb:
		ans = rb - (c + r)
	elif c - r >= lb and c + r >= rb:
		ans = c - r - lb
	elif c - r <= lb and c + r >= rb:
		ans = 0
	ans = max(ans, 0)
	print(ans)
t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	solve(a, b, c, r)


t = int(input())
for j in range(t):
	(a, b, c, r) = map(int, input().split())
	(x, y) = (c - r, c + r)
	if b >= a:
		if x > a and y < b:
			print(b - a - (y - x))
		elif x <= a and y >= b:
			print(0)
		elif x > a and y >= b and (x < b):
			print(b - a - (b - x))
		elif x <= a and y < b and (y > a):
			print(b - a - (y - a))
		else:
			print(b - a)
	elif a >= b:
		if x > b and y < a:
			print(a - b - (y - x))
		elif x <= b and y >= a:
			print(0)
		elif x > b and y >= a and (x < a):
			print(a - b - (a - x))
		elif x <= b and y < a and (y > b):
			print(a - b - (y - b))
		else:
			print(a - b)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	s = c - r
	e = c + r
	ans = 0
	S = max(a, s)
	E = min(b, e)
	if S > E:
		S = E
	print(b - a - E + S)


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


t = int(input())
for case in range(t):
	ans = 0
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(b, a) = (a, b)
	goes = b - a
	cover_start = c - r
	cover_finish = c + r
	if cover_finish <= a:
		ans = goes
	elif cover_start >= b:
		ans = goes
	elif cover_start >= a and cover_finish <= b:
		ans = goes - r - r
	elif cover_start <= a and cover_finish >= b:
		ans = 0
	elif cover_start <= a and cover_finish <= b and (cover_finish >= a):
		ans = b - cover_finish
	elif cover_finish >= b and cover_start >= a and (cover_start <= b):
		ans = cover_start - a
	else:
		print('Invalid state')
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	x = min(b - a, max(0, c - a - d) + max(0, b - c - d))
	print(x)


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(s, r) = (c - d, c + d)
	if a > r and b > r or (a < s and b < s):
		print(abs(a - b))
	else:
		ans = max(s - a, 0) + max(b - r, 0)
		print(ans)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	(a, b) = (min(a, b), max(a, b))
	if a <= left and right <= b:
		dis = b - a
		net = right - left
		print(max(0, dis - net))
	elif left <= b and right > b:
		dis = b - a
		net = b - left
		print(max(0, dis - net))
	elif right >= a and left < a:
		dis = b - a
		net = right - a
		print(max(0, dis - net))
	else:
		print(b - a)
t = int(input())
for _ in range(t):
	main()


cases = int(input())
for case in range(cases):
	values = list(map(lambda x: int(x), input().split()))
	(a, b, c, r) = values
	if a > b:
		(a, b) = (b, a)
	(radar_min, radar_max) = (c - r, c + r)
	if a >= radar_min and a <= radar_max:
		a = radar_max
	if b <= radar_max and b >= radar_min:
		b = radar_min
	result = b - a
	if a <= radar_min and b >= radar_max:
		result -= radar_max - radar_min
	if result < 0:
		result = 0
	print(result)


test = int(input())
for _ in range(test):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if c < a:
		print(min(max(b - c - d, 0), b - a))
	elif c > b:
		print(min(max(c - a - d, 0), b - a))
	else:
		print(b - a - min(c - a, d) - min(b - c, d))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	m = c - r
	n = c + r
	t = 0
	mi = min(a, b)
	ma = max(a, b)
	if n == mi:
		print(ma - mi)
	elif n < mi:
		print(ma - mi)
	elif ma < m:
		print(ma - mi)
	elif ma == m:
		print(ma - mi)
	else:
		if m > mi:
			t += m - mi
		if ma > n:
			t += ma - n
		print(t)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	print(min(b - a, max(c - r - a, 0) + max(b - (c + r), 0)))


for _ in range(int(input())):
	(a, b, point, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	b -= a
	point -= a
	(point1, point2) = (point - r, point + r)
	ans = b
	if point1 <= 0:
		point1 = 0
	if point2 >= b:
		point2 = b
	if point2 - point1 < 0:
		(point1, point2) = (0, 0)
	print(ans - (point2 - point1))


import sys
from math import *
ds_input = sys.stdin.readline

def overlap(min1, max1, min2, max2):
	return max(0, min(max1, max2) - max(min1, min2))
t = int(ds_input())
s = ''
for _ in range(0, t):
	(a, b, c, r) = map(int, ds_input().split())
	l = int(c - r)
	r = int(c + r)
	ret = abs(a - b) - overlap(min(a, b), max(a, b), l, r)
	s += str(ret) + '\n'
print(s)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(c_min, c_max) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	c_min = max(a, c_min)
	c_min = min(b, c_min)
	c_max = min(b, c_max)
	c_max = max(a, c_max)
	print(c_min - a + b - c_max)


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(i) for i in input().split()]
	left = c - r
	right = c + r
	start_point = max(left, min(a, b))
	end_point = min(right, max(a, b))
	diff = end_point - start_point
	print(abs(b - a) - max(0, diff))


T = int(input())
for _ in range(T):
	(a, b, c, r) = list(map(int, input().split()))
	(c1, c2) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	c1 = max(c1, a)
	c2 = min(c2, b)
	if c2 - c1 > 0:
		print(b - a - (c2 - c1))
	else:
		print(b - a)


import sys
q = int(input())
for _ in range(q):
	(a, b, c, r) = map(int, input().split())
	if a == b:
		print(0)
		continue
	(a, b) = (min(a, b), max(a, b))
	if c < a:
		if c + r <= a:
			print(b - a)
			continue
		elif c + r <= b:
			print(b - c - r)
			continue
		else:
			print(0)
			continue
	elif a <= c and c <= b:
		aa = max(a, c - r)
		bb = min(b, c + r)
		covered = bb - aa
		res = b - a - covered
		print(res if res > 0 else 0)
		continue
	elif c - r >= b:
		print(b - a)
		continue
	elif c - r <= a:
		print(0)
		continue
	else:
		bb = c - r
		print(bb - a)
		continue


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
	elif c <= a:
		if a - c >= r:
			print(b - a)
		else:
			print(max(b - a - (r - (a - c)), 0))
	elif c >= b:
		if c - b >= r:
			print(b - a)
		else:
			print(max(b - a - (r - (c - b)), 0))
	else:
		if c - a - r >= 0:
			x1 = c - a - r
		else:
			x1 = 0
		if b - c - r >= 0:
			x2 = b - c - r
		else:
			x2 = 0
		x = x1 + x2
		print(x)


a = int(input())

def overlap(min1, max1, min2, max2):
	return max(0, min(max1, max2) - max(min1, min2))
for x in range(a):
	ar = []
	for y in input().split(' '):
		ar.append(int(y))
	diff = abs(ar[1] - ar[0])
	minR = ar[2] - ar[3]
	maxR = ar[2] + ar[3]
	if ar[0] < ar[1]:
		print(diff - overlap(ar[0], ar[1], minR, maxR))
	else:
		print(diff - overlap(ar[1], ar[0], minR, maxR))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ans = b - a
	left = c - r
	right = c + r
	if right <= a:
		print(ans)
		continue
	if b <= left:
		print(ans)
		continue
	tmp = min(right, b) - max(left, a)
	print(max(ans - tmp, 0))


def distance(a, b, c, r):
	edge1 = c - r
	edge2 = c + r
	if a == b:
		return 0
	elif edge1 <= a <= edge2 and edge1 <= b <= edge2 or (edge2 <= a <= edge1 and edge2 <= b <= edge1):
		return 0
	elif a < b:
		if a <= edge1 <= b and a <= edge2 <= b:
			return b - a - 2 * r
		elif a <= edge1 <= b:
			return -a + edge1
		elif a <= edge2 <= b:
			return b - edge2
		else:
			return abs(a - b)
	elif b < a:
		if b <= edge1 <= a and b <= edge2 <= a:
			return a - b - 2 * r
		elif b <= edge1 <= a:
			return -b + edge1
		elif b <= edge2 <= a:
			return a - edge2
		else:
			return abs(a - b)
t = int(input())
for i in range(t):
	seq = input()
	arr = [int(x) for x in seq.split()]
	print(distance(arr[0], arr[1], arr[2], arr[3]))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	x = max(a, b)
	y = min(a, b)
	p = c + r
	q = c - r
	if q >= y and q <= x:
		a1 = x - q
		if a1 > 2 * r:
			a1 = 2 * r
	elif p >= y and p <= x:
		a1 = p - y
		if a1 > 2 * r:
			a1 = 2 * r
	elif p >= x and q <= y:
		a1 = x - y
	else:
		a1 = 0
	print(x - y - a1)


t = int(input())
results = []
for i in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	start = min(a, b)
	end = max(a, b)
	c_l = c - r
	c_u = c + r
	if c_u <= start:
		res = end - start
	elif c_l <= start:
		if c_u <= end:
			start = c_l
			res = end - start - 2 * r
		else:
			res = 0
	elif c_u <= end:
		res = end - start - 2 * r
	elif c_l <= end:
		end = c_u
		res = end - start - 2 * r
	else:
		res = end - start
	results.append(str(res))
print('\n'.join(results))


for j in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	m = max(a, b)
	n = min(a, b)
	if n == m:
		print(0)
		continue
	elif c + r < n:
		print(abs(n - m))
	elif c - r > m:
		print(abs(n - m))
	elif n >= c - r and m <= c + r:
		print(0)
	elif n >= c - r and n <= c + r and (m > c + r):
		print(m - c - r)
	elif n < c - r and m >= c - r and (m <= c + r):
		print(c - r - n)
	elif n < c - r and m > c + r:
		print(m - n - r - r)


def solve():
	(a, b, c, r) = map(int, input().split())
	(p, q) = (min(a, b), max(a, b))
	(L, R) = (c - r, c + r)
	(st, ed) = (max(L, p), min(R, q))
	print(abs(a - b) - max(0, ed - st))
for _ in range(int(input())):
	solve()


import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
INF = 1 << 60
t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	(a, b) = (min(a, b), max(a, b))
	if b <= left or a >= right:
		print(b - a)
		continue
	ans = b - a - (min(right, b) - max(left, a))
	print(ans)


for _ in range(int(input())):
	(a, b, c, d) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	print(min(b - a, max(0, c - d - a) + max(0, b - d - c)))


n = int(input())
for _ in range(n):
	(a, b, c, r) = map(int, input().split())
	dist = abs(a - b)
	if min(a, b) < c < max(a, b):
		d = min(abs(a - c), abs(b - c))
		if d >= r:
			ans = dist - r * 2
		else:
			ans = dist - r - d
	elif c <= min(a, b):
		d = r - abs(min(a, b) - c)
		if d < 0:
			d = 0
		ans = dist - d
	else:
		d = r - abs(max(a, b) - c)
		if d < 0:
			d = 0
		ans = dist - d
	print(ans if ans >= 0 else 0)


def getOverlap(a, b):
	return max(0, min(a[1], b[1]) - max(a[0], b[0]))
for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	lower = c - d
	upper = c + d
	common = getOverlap([lower, upper], [a, b])
	print(b - a - common)


def find_no_coverage_time(a, b, c, r):
	maximum = max(a, b)
	minimum = min(a, b)
	lowest_range = max(minimum, c - r)
	highest_range = min(maximum, c + r)
	full_trip = maximum - minimum
	covered_trip = highest_range - lowest_range
	if highest_range < minimum or lowest_range > maximum:
		return full_trip
	return full_trip - covered_trip

def solution(inp):
	return find_no_coverage_time(inp[0], inp[1], inp[2], inp[3])

def main():
	length = eval(input())
	result = []
	for i in range(length):
		result += [solution(list(map(int, input().split())))]
	print(*result, sep='\n')
main()


import math
import bisect
from collections import defaultdict
from collections import OrderedDict
for _ in range(int(input())):
	(a1, b1, c, r) = map(int, input().split())
	ans = 0
	x1 = c - r
	x2 = c + r
	a = min(a1, b1)
	b = max(a1, b1)
	if x1 > b or x2 < a:
		print(b - a)
	elif a < b:
		if x1 > a:
			ans += x1 - a
		if x2 < b:
			ans += b - x2
		print(ans)
	else:
		if x1 > b:
			ans += x1 - b
		if x2 < a:
			ans += a - x2
		print(ans)


def main():
	t = int(input())
	for i in range(t):
		(a, b, c, r) = map(int, input().split())
		L = c - r
		R = c + r
		lb = max(L, min(a, b))
		rb = min(R, max(a, b))
		print(abs(a - b) - max(0, rb - lb))
main()


num_tests = int(input())
for i in range(num_tests):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if c < a:
		if c + r >= a:
			start = a
			end = min(c + r, b)
			distance_covered = end - start
		else:
			distance_covered = 0
	elif b < c:
		if c - r < b:
			start = max(c - r, a)
			end = b
			distance_covered = end - start
		else:
			distance_covered = 0
	else:
		start = max(a, c - r)
		end = min(b, c + r)
		distance_covered = end - start
	total_distance = b - a
	uncovered_distance = total_distance - distance_covered
	print(uncovered_distance)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	x = max(c - r, a)
	y = min(c + r, b)
	if x > y:
		print(b - a)
	else:
		print(b - a - (y - x))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	n = b - a
	(l, f) = (c - r, c + r)
	if a > l:
		(a, b, l, f) = (l, f, a, b)
	if l >= b:
		print(n)
	elif f <= b:
		print(n - (f - l))
	else:
		print(n - (b - l))


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	print(abs(a - b) - abs(min(b, max(a, c + d)) - max(a, min(b, c - d))))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	a1 = min(a, b)
	b1 = max(a, b)
	c1 = c - r
	c2 = c + r
	cover = 0
	if c2 >= a1 and c1 <= b1:
		cover = abs(min(c2, b1) - max(c1, a1))
	print(abs(b1 - a1) - cover)


n = int(input())
for i in range(n):
	(a, b, c, r) = [i for i in map(int, input().split())]
	if a > b:
		(a, b) = (b, a)
	f_d_l = c - r
	f_d_h = c + r
	res = 0
	if a < f_d_l < b:
		res += f_d_l - a
	if a < f_d_h < b:
		res += b - f_d_h
	if res == 0:
		if f_d_l <= a and b <= f_d_h:
			print(res)
		else:
			print(b - a)
	else:
		print(res)


t = int(input())
l2 = []
for i in range(t):
	(a1, b1, c, r) = map(int, input().split())
	b = min(a1, b1)
	a = max(a1, b1)
	k = 0
	if c >= b and c <= a:
		if c - b <= r:
			k += 0
		else:
			k += c - b - r
		if a - c <= r:
			k += 0
		else:
			k += a - c - r
	elif c >= a and c >= b:
		if c - b <= r:
			k = 0
		else:
			k = c - b - r
			if c - a <= r:
				k += 0
			else:
				k = a - b
	elif c <= a and c <= b:
		if a - c <= r:
			k += 0
		else:
			k += a - c - r
			if b - c <= r:
				k += 0
				k = a - c - r
			else:
				k = a - b
	else:
		pass
	l2.append(k)
for i in range(t):
	print(l2[i])


n = int(input())
for l in range(n):
	(a, b, c, r) = map(int, input().split(' '))
	mins = 0
	beg = c - r
	end = c + r
	if a > b:
		(a, b) = (b, a)
	if beg < a and end < a or (beg > b and beg > a):
		print(b - a)
	elif beg < a and a <= end <= b:
		print(b - end)
	elif a <= beg <= end <= b:
		print(beg - a + b - end)
	elif a <= beg <= b and end > b:
		print(beg - a)
	else:
		print(0)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = sorted([a, b])
	(d, e) = (c - r, c + r)
	print(b - a - max(0, min(b, e) - max(a, d)))


try:
	import math
	t = int(input())
	for _ in range(t):
		ans = 0
		(a, b, c, r) = [int(i) for i in input().split(' ')]
		t1 = max(a, b)
		t2 = min(a, b)
		a = t2
		b = t1
		if a == b:
			ans = 0
		elif c + r < a or c - r > b:
			ans = b - a
		elif c - r >= a and c + r <= b:
			ans = b - a - r - r
		elif c - r < a and c + r < b:
			ans = b - (c + r)
		elif c - r > a and c + r >= b:
			ans = c - r - a
		else:
			ans = 0
		print(ans)
except:
	pass


def solve():
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if r == 0:
		print(b - a)
	elif a >= c + r or b <= c - r:
		print(b - a)
	elif a <= c - r and b >= c - r and (b <= c + r):
		print(c - a - r)
	elif a >= c - r and b >= c + r:
		print(b - c - r)
	elif a >= c - r and b <= c + r:
		print(0)
	else:
		print(b - a - 2 * r)
t = int(input())
for _ in range(t):
	solve()


import sys
from random import choice, randint
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, sys.stdin.readline().strip().split())

def LI():
	return list(map(int, sys.stdin.readline().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().strip().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().strip().split()]

def LS():
	return sys.stdin.readline().strip().split()

def I():
	return int(sys.stdin.readline().strip())

def F():
	return float(sys.stdin.readline().strip())

def S():
	return sys.stdin.readline().strip()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))
inp = sys.stdin.readline
out = sys.stdout.write

def main():
	t = I()
	for _ in range(t):
		(a, b, c, r) = MI()
		(x, y) = (c - r, c + r)
		(k, l) = (min(a, b), max(a, b))
		ans = 0
		if k <= c <= l:
			if x <= k and y >= l:
				ans = 0
			else:
				if x - k >= 0:
					ans += x - k
				if l - y >= 0:
					ans += l - y
		if c > k and c > l:
			if x <= k and x <= l:
				ans = 0
			elif x > k and x > l:
				ans = l - k
			else:
				ans = x - k
		if c < k and c < l:
			if y >= k and y >= l:
				ans = 0
			elif y < k and y < l:
				ans = l - k
			else:
				ans = l - y
		print(ans)
main()


t = int(input())
for case in range(t):
	(a, b, c, r) = [int(x) for x in input().split(' ')]
	(a, b) = (min(a, b), max(a, b))
	s = b - a - (max(min(b, r + c), a) - min(max(a, c - r), b))
	print(s)


for _ in range(int(input())):
	k = list(map(int, input().split()))
	p = min(k[0], k[1])
	q = max(k[0], k[1])
	m = k[2] + k[3]
	n = k[2] - k[3]
	if k[0] == k[1]:
		print(0)
	elif n <= p and m >= q:
		print(0)
	elif n >= p and m <= q:
		print(abs(p - n) + abs(q - m))
	elif n <= p and m <= q and (m >= p):
		print(abs(q - m))
	elif n >= p and m >= q and (n <= q):
		print(abs(p - n))
	elif n <= p and m <= p:
		print(abs(k[0] - k[1]))
	elif n >= q and m >= q:
		print(abs(k[0] - k[1]))


from math import ceil
from math import factorial
from collections import Counter
from operator import itemgetter
ii = lambda : int(input())
iia = lambda : list(map(int, input().split()))
isa = lambda : list(input().split())
t = ii()
for _ in range(t):
	(a, b, c, r) = iia()
	(a, b) = (min(a, b), max(a, b))
	c1 = c - r
	c2 = c + r
	if r == 0:
		x = abs(a - b)
	else:
		x = min(abs(a - b), abs(a - b) - (c - max(c1, a)) - (min(c2, b) - c))
	print(x)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	(l, R) = (c - r, c + r)
	st = max(l, min(a, b))
	d = min(R, max(a, b))
	print(abs(b - a) - max(0, d - st))


T = int(input())
for i in range(T):
	x = list(map(int, input().split()))
	(a, b, c, r) = (x[0], x[1], x[2], x[3])
	up = c + r
	low = c - r
	if a > b:
		(b, a) = (a, b)
	st = max(low, a)
	end = min(up, b)
	t = b - a - max(0, end - st)
	print(t)


T = int(input())
while T:
	(a, b, c, r) = map(int, input().split())
	if a > b:
		x = b
		b = a
		a = x
	len = 0
	high = c + r
	low = c - r
	if a > c + r or b < c - r:
		print(b - a)
		T -= 1
		continue
	low = c - r
	high = c + r
	if low > a:
		len += low - a
	if high < b:
		len += b - high
	print(len)
	T -= 1


n = int(input())
while n:
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	if a > b:
		(a, b) = (b, a)
	print(abs(a - b) - max(0, min(right, b) - max(left, a)))
	n -= 1


n = int(input())
while n > 0:
	n -= 1
	s = input()
	v = []
	v = s.split()
	a = int(v[0])
	b = int(v[1])
	c = int(v[2])
	r = int(v[3])
	if a > b:
		t = a
		a = b
		b = t
	sol = b - a
	t1 = c - r
	t2 = c + r
	if t2 >= a and t2 <= b:
		t1 = max(t1, a)
		sol -= t2 - t1
	elif t1 >= a and t1 <= b:
		t2 = min(t2, b)
		sol -= t2 - t1
	elif t1 <= a and t2 >= b:
		sol = 0
	print(str(sol))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	m = min(a, b, c)
	a -= m
	b -= m
	c -= m
	if a > b:
		(a, b) = (b, a)
	res = b - a
	(l, r) = (c - r, c + r)
	if a <= l <= b or a <= r <= b or l <= a <= r or (l <= b <= r):
		res -= min(b, r) - max(a, l)
	print(res)


def main():
	(st, finish, c, r) = map(int, input().split())
	if st > finish:
		(st, finish) = (finish, st)
	res = finish - st - max(0, min(finish, c + r) - max(st, c - r))
	print(res)
count = int(input())
for _ in range(count):
	main()


number = int(input())
result = []
for m in range(number):
	s = 0
	(a, b, c, r) = map(int, input().split())
	if a > b:
		d = a
		a = b
		b = d
	if a <= c <= b:
		if c - r > a:
			s += r
		else:
			s += c - a
		if c + r > b:
			s += b - c
		else:
			s += r
	elif c < a:
		if c + r >= b:
			s += b - a
		elif b > c + r > a:
			s += c + r - a
	elif c > a:
		if c - r <= a:
			s += b - a
		elif a < c - r < b:
			s += b - (c - r)
	t = b - a - s
	result.append(t)
for u in result:
	print(u)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	L = max(min(a, b), c - r)
	R = min(max(a, b), c + r)
	print(max(a, b) - min(a, b) - max(0, R - L))


T = 1
T = int(input())
for t in range(1, T + 1):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	if c + r <= a or c - r >= b:
		time = b - a
	elif c - r <= a and c + r >= b:
		time = 0
	elif c - r <= a and c + r < b:
		time = b - c - r
	elif c - r > a and c + r >= b:
		time = c - r - a
	else:
		time = b - a - 2 * r
	print(time)


output = ''
t = int(input())

def f(a, b, c, r):
	if c + r - a < 0 or c - r - b > 0:
		return b - a
	elif c + r - a >= 0 and c - r - a <= 0 and (c + r - b <= 0):
		return b - (c + r)
	elif c - r - a >= 0 and c + r - b <= 0:
		return b - c - r + c - r - a
	elif c - r - a >= 0 and c + r - b >= 0 and (c - r - b <= 0):
		return c - r - a
	elif c - r - a <= 0 and c + r - b >= 0:
		return 0
	return 0
for i in range(0, t):
	(a, b, c, r) = [int(a) for a in input().split()]
	(a, b) = (min(a, b), max(a, b))
	output = output + str(f(a, b, c, r)) + '\n'
print(output)


t = int(input())
for _ in range(0, t):
	(a, b, c, r) = [int(x) for x in input().split()]
	l = c - r
	h = c + r
	if a > b:
		(a, b) = (b, a)
	if l >= a and l <= b and (h >= a) and (h <= b):
		print(l - a + (b - h))
	elif l >= a and l <= b and (h >= b):
		print(l - a)
	elif h >= a and h <= b and (l <= a):
		print(b - h)
	elif l > b:
		print(b - a)
	elif h < a:
		print(b - a)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	if b < a:
		(a, b) = (b, a)
	k = min(c + r, b) - max(c - r, a)
	d = b - a
	if k <= 0:
		print(d)
	else:
		print(d - k)


import math
t = int(input())
for qq in range(t):
	(a, b, c, r) = map(int, input().split(' '))
	t = 0
	st = c - r
	ed = c + r
	st = max(min(a, b), st)
	ed = min(max(a, b), ed)
	print(abs(a - b) - max(0, ed - st))


t = int(input())
p = []
for i in range(t):
	(a, b, c, r) = [int(j) for j in input().split()]
	if a > b:
		(a, b) = (b, a)
	a1 = c - r
	b1 = c + r
	if a >= a1:
		if b <= b1:
			p.append(0)
		elif b1 < a:
			p.append(b - a)
		else:
			p.append(b - b1)
	elif a1 < b < b1:
		p.append(a1 - a)
	elif b < b1:
		p.append(b - a)
	else:
		p.append(b - a - b1 + a1)
for i in p:
	print(i)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(r1, r2) = (c - r, c + r)
	mx = max(a, b)
	(a, b) = (min(a, b), mx)
	dist = 0
	if a < r1:
		dist += r1 - a
	if r2 < b:
		dist += b - r2
	if r2 <= a or r1 >= b:
		dist = b - a
	print(dist)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	mr = c + r
	ml = c - r
	ans = 0
	if max(a, b) - mr >= 0 and mr >= min(a, b):
		ans += max(a, b) - mr
	if ml - min(a, b) >= 0 and ml <= max(a, b):
		ans += ml - min(a, b)
	if ml >= max(a, b) or mr <= min(a, b):
		ans = abs(a - b)
	print(ans)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
t = int(input())
while t > 0:
	(a, b, c, r) = input().split(' ')
	a = int(a)
	b = int(b)
	c = int(c)
	r = int(r)
	ans = 0
	if a < b:
		startpos = a
		endpos = b
	else:
		startpos = b
		endpos = a
	if r == 0:
		ans = endpos - startpos
	elif startpos != endpos:
		if c <= startpos:
			temp1 = c + r
			if temp1 >= endpos:
				ans = 0
			else:
				ans = endpos - max(startpos, temp1)
		elif c >= endpos:
			temp2 = c - r
			if temp2 <= startpos:
				ans = 0
			else:
				ans = min(endpos, temp2) - startpos
		elif c > startpos and c < endpos:
			temp1pos = c - r
			temp2pos = c + r
			if temp1pos <= startpos and temp2pos >= endpos:
				ans = 0
			elif temp2pos >= endpos and temp1pos > startpos:
				ans = temp1pos - startpos
			elif temp2pos < endpos and temp1pos <= startpos:
				ans = endpos - temp2pos
			elif temp2pos < endpos and temp1pos > startpos:
				ans = endpos - temp2pos + (temp1pos - startpos)
	print(ans)
	t = t - 1


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(b, a) = (a, b)
	(A, B) = (c + d, c - d)
	print(max(0, min(B - a, b - a)) + max(0, min(b - A, b - a)))


t = int(input())
for j in range(0, t):
	inps = input().split(' ')
	(a, b, c, r) = (int(inps[0]), int(inps[1]), int(inps[2]), int(inps[3]))
	if a > b:
		(a, b) = (b, a)
	if c - r <= a and c + r >= b:
		print(0)
	elif a <= c - r and b >= c + r:
		print(b - a - 2 * r)
	elif c - r < a and c + r > a:
		print(b - (c + r))
	elif c - r < b and c + r > b:
		print(c - r - a)
	else:
		print(b - a)


t = int(input())
ans_arr = []
for x in range(t):
	[a, b, c, r] = [int(i) for i in input().split()]
	A = min(a, b)
	B = max(a, b)
	if c + r < A or c - r > B:
		ans_arr.append(str(B - A))
	else:
		answer = B - A - (min(B, c + r) - max(A, c - r))
		ans_arr.append(str(answer))
print('\n'.join(ans_arr))


n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	s = min(a, b)
	l = max(a, b)
	if s <= c - r and l <= c - r or (s >= c + r and l >= c + r):
		result = abs(l - s)
	elif s <= c - r and l >= c - r and (l <= c + r):
		result = abs(c - r - s)
	elif s >= c - r and s <= c + r and (l >= c + r):
		result = abs(l - c - r)
	elif s >= c - r and s <= c + r and (l >= c - r) and (l <= c + r):
		result = 0
	else:
		result = abs(c - r - s) + abs(l - r - c)
	print(result)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
for _ in range(int(input())):
	(a, b, c2, r2) = map(int, input().split())
	c1 = (a + b) / 2
	r1 = abs(c1 - a)
	d = abs(c1 - c2)
	if d < r1 + r2 and d > abs(r1 - r2):
		print(int(2 * r1 - (r1 + r2 - d)))
	elif d >= r1 + r2:
		print(int(2 * r1))
	elif r1 > r2:
		print(int(2 * abs(r1 - r2)))
	else:
		print(0)


q = int(input())

def solve():
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	p1 = c - r
	p2 = c + r
	if p1 >= a and p2 <= b:
		print(p1 - a + b - p2)
	elif a < p1 < b < p2:
		print(p1 - a)
	elif b > p2 > a > p1:
		print(b - p2)
	elif p1 <= a and p2 >= b:
		print(0)
	else:
		print(b - a)
while q:
	solve()
	q -= 1


def solve():
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if a <= c and b >= c:
		left = c - r - a
		right = b - c - r
		if left < 0:
			left = 0
		if right < 0:
			right = 0
		print(left + right)
	elif b <= c:
		left = b - a
		right = b - c + r
		if right < 0:
			right = 0
		if left - right < 0:
			right = left
		print(left - right)
	else:
		left = b - a
		right = c + r - a
		if right < 0:
			right = 0
		if left - right < 0:
			right = left
		print(left - right)
t = int(input())
while t > 0:
	solve()
	t -= 1


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = sorted([a, b])
	left = min(max(c - r, a), b)
	right = max(min(c + r, b), a)
	length = abs(left - right)
	print(max(abs(b - a) - length, 0))


from math import *
import os, sys
from io import BytesIO
sys.setrecursionlimit(10 ** 9)
for i in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	c1 = c - r
	c2 = c + r
	d1 = max(min(a, b), min(c1, c2))
	d2 = min(max(a, b), max(c1, c2))
	print(abs(b - a) - max(d2 - d1, 0))


import sys
inp = sys.stdin.readline
ans = ''
for _ in range(int(inp())):
	(a, b, c, r) = map(int, inp().split())
	(a, b) = sorted([a, b])
	st = max(c - r, min(a, b))
	ed = min(c + r, max(a, b))
	ans += str(abs(b - a) - max(0, ed - st)) + '\n'
print(ans)


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(a, b, c, r) = value()
	(a, b) = sorted((a, b))
	l = c - r
	r = c + r
	tot = b - a
	ans = 0
	if a <= l:
		ans += min(l, b) - a
	if r <= b:
		ans += b - max(r, a)
	print(ans)


for tests in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	d = 0
	if c < a:
		if c + r >= b:
			d = b - a
		elif c + r <= a:
			d = 0
		else:
			d = c + r - a
	elif c > b:
		if c - r <= a:
			d = b - a
		elif c - r >= b:
			d = 0
		else:
			d = b + r - c
	else:
		d = -max(c - r, a) + min(c + r, b)
	print(b - a - d)


def get_nn_sum(a, b, rng):
	if a > b:
		return get_nn_sum(b, a, rng)
	if a > rng[1] or b < rng[0]:
		return b - a
	return max(rng[0] - a, 0) + max(b - rng[1], 0)
for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	print(get_nn_sum(a, b, (c - r, c + r)))


cases = int(input())
for _ in range(cases):
	(start, end, tower, radius) = map(int, input().split(' '))
	if start > end:
		(start, end) = (end, start)
	tower_range = [tower - radius, tower + radius]
	if tower_range[0] >= end or tower_range[1] <= start:
		print(end - start)
	else:
		print(end - start - (min(tower_range[1], end) - max(start, tower_range[0])))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	t = inin()
	for _ in range(t):
		(a, b, c, d) = cin()
		e = c - d
		f = c + d
		if a > b:
			(a, b) = (b, a)
		j = min(e, b)
		k = max(f, a)
		ans = 0
		ans += max(j - a, 0)
		ans += max(b - k, 0)
		print(ans)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


v = int(input())
while v > 0:
	ta = input().split()
	A = int(ta[0])
	B = int(ta[1])
	f = int(ta[2])
	r = int(ta[3])
	C = f + r
	D = f - r
	c = min(C, D)
	d = max(C, D)
	a = min(A, B)
	b = max(A, B)
	if r == 0:
		print(b - a)
	elif c >= b:
		print(b - a)
	elif d <= a:
		print(b - a)
	elif (c < b and b <= d) and c >= a:
		print(c - a)
	elif (c <= a and a < d) and d <= b:
		print(b - d)
	elif a <= c and d <= b:
		print(c - a + (b - d))
	elif a >= c and b <= d:
		print('0')
	v -= 1


def abonent(arr):
	a = int(arr[0])
	b = int(arr[1])
	c = int(arr[2])
	r = int(arr[3])
	c1 = c - r
	c2 = c + r
	if c1 <= a <= c2 and c1 <= b <= c2 or (c2 <= a <= c1 and c2 <= b <= c1):
		return 0
	elif a <= c1 <= b and a <= c2 <= b or (b < c1 <= a and b <= c2 <= a):
		return abs(b - a) - 2 * r
	elif c1 <= a <= c2:
		if b > c2:
			return abs(b - c2)
		else:
			return abs(b - c1)
	elif c1 <= b <= c2:
		if a > c2:
			return abs(a - c2)
		else:
			return abs(a - c1)
	else:
		return abs(b - a)
t = int(input())
a = [input().split(' ') for j in range(t)]
for i in range(t):
	print(abonent(a[i]))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ans = b - a
	if r == 0:
		print(ans)
		continue
	if c >= a and c <= b:
		ans -= min(b, c + r) - max(a, c - r)
	elif c < a:
		ans -= min(max(a, c + r), b) - a
	else:
		ans -= b - max(min(b, c - r), a)
	print(ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(a, b, c, r) = inputnums()
	if b < a:
		cur = a
		a = b
		b = cur
	x = max(c - r, a)
	y = min(c + r, b)
	if c + r <= a or c - r >= b:
		print(b - a)
	else:
		print(b - a - (y - x))


for _ in range(int(input())):
	l = list(map(int, input().split()))
	(a, b, c, r) = (l[0], l[1], l[2], l[3])
	if a > b:
		(a, b) = (b, a)
	if c <= a:
		if c + r < a:
			print(b - a)
		elif c + r >= a and c + r <= b:
			print(b - (c + r))
		else:
			print('0')
	elif c >= b:
		if c - r >= b:
			print(b - a)
		elif c - r >= a and c - r <= b:
			print(c - r - a)
		else:
			print('0')
	else:
		x = c - r
		y = c + r
		sum = 0
		if x >= a:
			sum += x - a
		if y <= b:
			sum += b - y
		print(sum)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	x = c - r
	y = c + r
	if a > b:
		(a, b) = (b, a)
	z = max(0, min(y, b) - max(x, a))
	print(b - a - z)


def solve(a, b, c, r):
	(a, b) = (min([a, b]), max([a, b]))
	(c_start, c_stop) = (c - r, c + r)
	total = 0
	if b < c_start or c_stop < a:
		return b - a
	if a >= c_start and b <= c_stop:
		return 0
	if a < c_start:
		total += c_start - a
	if b > c_stop:
		total += b - c_stop
	return total
T = int(input().strip())
res = []
for _ in range(T):
	(a, b, c, r) = map(int, input().strip().split(' '))
	res.append(solve(a, b, c, r))
for r in res:
	print(r)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(f, e) = (c - r, c + r)
	if a > b:
		(a, b) = (b, a)
	f = min(b, max(f, a))
	e = max(a, min(e, b))
	x = max(0, f - a)
	y = max(0, b - e)
	print(x + y)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	low = c - r
	high = c + r
	if a > b:
		ci = a
		a = b
		b = ci
	if low > b or high < a:
		print(b - a)
		continue
	if low >= a and high <= b:
		print(b - a - (high - low))
		continue
	if low <= a and high >= b:
		print(0)
		continue
	if low >= a and low <= b and (high > b):
		print(low - a)
		continue
	if low < a and high >= a and (high <= b):
		print(b - high)
		continue


import sys
input = sys.stdin.readline

def main():
	t = int(input())

	def intersec(a, b, c, d):
		st = max(a, c)
		nd = min(b, d)
		return max(0, nd - st)
	for _ in range(t):
		(a, b, c, r) = map(int, input().split())
		if a > b:
			(a, b) = (b, a)
		print(b - a - intersec(a, b, c - r, c + r))
main()


t = int(input())
for i in range(t):
	(a, b, x, r) = map(int, input().split())
	(a, b) = (a, b) if a < b else (b, a)
	(c, d) = (x - r, x + r)
	nachalo = c - a
	nachalo = max(0, nachalo)
	nachalo = min(b - a, nachalo)
	konec = b - d
	konec = max(0, konec)
	konec = min(b - a, konec)
	print(nachalo + konec)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		t = a
		a = b
		b = t
	k = abs(min(a, b, c - r))
	a += k
	b += k
	c += k
	if c + r < a or c - r > b:
		print(b - a)
	else:
		print(b - a - abs(min(b, c + r) - max(a, c - r)))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	m = min(a, b, c)
	(a, b, c) = (a - m, b - m, c - m)
	m = min(a, b)
	ma = max(a, b)
	a = m
	b = ma
	if c >= a and c >= b:
		if c - b > r:
			print(b - a)
		elif c - a > r:
			print(b - a - b + c - r)
		else:
			print(0)
	elif c >= a and c <= b:
		print(b - a - min(c - a, r) - min(b - c, r))
	elif c <= a:
		if a - c > r:
			print(b - a)
		elif b - c > r:
			print(b - a - c - r + a)
		else:
			print(0)


import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
q = I()
for _ in range(q):
	(a, b, c, dist) = readInts()
	l = c - dist
	r = c + dist
	if a <= b:
		pass
	else:
		(a, b) = (b, a)
	if a <= l <= r <= b:
		print(max(0, b - a + 1 - (r - l + 1)))
	elif l <= b and b <= r:
		print(max(0, l - a))
	elif l <= a and a <= r:
		print(max(0, b - r))
	else:
		print(b - a)


t = int(input())
for i in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	if a == b:
		print(0)
	elif c + r <= a or c - r >= b:
		print(b - a)
	else:
		print(b - a - max(min(b, c + r) - max(a, c - r), 0))


from sys import stdin
from math import ceil, gcd
for _ in range(int(stdin.readline())):
	(a, b, c, r) = map(int, stdin.readline().split())
	(L, R) = (c - r, c + r)
	A = min(a, b)
	B = max(a, b)
	ans = B - A
	if A >= R or B <= L:
		pass
	elif L <= A and R <= B and (R >= A):
		ans -= R - A
	elif L >= A and R >= B and (L <= B):
		ans -= B - L
	elif L <= A and R >= B:
		ans = 0
	else:
		ans -= R - L
	print(ans)


for i in range(int(input())):
	x = [int(j) for j in input().split()]
	r = x[3]
	a = x[0]
	b = x[1]
	c = x[2]
	ab = abs(x[0] - x[1])
	ac = abs(x[0] - x[2])
	bc = abs(x[1] - x[2])
	m = min(ac, bc)
	mx = max(ac, bc)
	if (a >= c >= b or a <= c <= b) and r <= m:
		print(ab - 2 * r)
	elif (a >= c >= b or a <= c <= b) and m < r <= mx:
		print(mx - r)
	elif (c >= a or c <= a) and (c <= b or c >= b) and (0 <= r <= m):
		print(ab)
	elif (c >= a or c <= a) and (c <= b or c >= b) and (m < r <= mx):
		print(ab + m - r)
	else:
		print(0)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(a, b, c, r) = mints()
	if a > b:
		(a, b) = (b, a)
	return b - a - max(min(c + r, b) - max(c - r, a), 0)
for i in range(mint()):
	print(solve())


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	(a, b, c, r) = (l[0], l[1], l[2], l[3])
	if a > b:
		(a, b) = (b, a)
	total = b - a
	if a < c and b > c:
		if c + r > b:
			total -= b - c
		else:
			total -= r
		if c - r < a:
			total -= c - a
		else:
			total -= r
	if c <= a:
		if c + r > a:
			total -= c + r - a
	if c >= b:
		if c - r < b:
			total -= b - c + r
	if a == b and b == c:
		print(0)
		continue
	if total < 0:
		print(0)
		continue
	print(total)


def func(abcr):
	(a, b, c, r) = list(map(int, abcr.split()))
	coverage = []
	journey = []
	coverage = [i for i in range(c - r, c + r + 1)]
	journey = [i for i in range(min(a, b), max(a, b) + 1)]
	coverage = [item for item in journey if item in coverage]
	journey_length = abs(a - b)
	if len(coverage) == 0:
		coverage_length = len(coverage)
	else:
		coverage_length = len(coverage) - 1
	return journey_length - coverage_length

def func2(abcr):
	(a, b, c, r) = list(map(int, abcr.split()))
	journey_length = abs(a - b)
	find_left = max(min(a, b), c - r) if c - r <= max(a, b) else max(a, b)
	find_right = min(max(a, b), c + r) if c + r >= min(a, b) else find_left
	coverage_length = find_right - find_left
	return journey_length - coverage_length

def main():
	t = int(input())
	t_input = [input() for i in range(t)]
	for i in list(map(func2, t_input)):
		print(i)
main()


T = int(input())
for i in range(T):
	(a, b, c, r) = map(int, input().strip().split())
	(a, b) = sorted((a, b))
	r1 = c - r
	r2 = c + r
	if c <= a:
		if r2 >= b:
			print(0)
			continue
		if r2 < a:
			print(b - a)
			continue
		print(b - r2)
	elif c >= b:
		if r1 > b:
			print(b - a)
			continue
		if r1 <= a:
			print(0)
			continue
		print(r1 - a)
	else:
		xx = max((b - r2, 0)) + max((r1 - a, 0))
		print(xx)


from sys import stdin, stdout
read = lambda : map(int, stdin.readline().split())
I = lambda : stdin.readline()
for _ in range(int(I())):
	(a, b, c, r) = read()
	(a, b) = (a, b) if a < b else (b, a)
	(c1, c2) = (c - r, c + r)
	c1_inside = a <= c1 and c1 <= b
	c2_inside = a <= c2 and c2 <= b
	if c1_inside:
		if c2_inside:
			print(c1 - a + b - c2)
		else:
			print(c1 - a)
	elif c2_inside:
		print(b - c2)
	elif c1 <= a and c2 >= b:
		print(0)
	else:
		print(b - a)


def solve(a, b, c, r):
	res = min(c + r, b) - max(c - r, a)
	if res > 0:
		print(b - a - res)
	else:
		print(b - a)
n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	if a < b:
		solve(a, b, c, r)
	else:
		solve(b, a, c, r)


n = int(input())
for _ in range(n):
	(a, b, m, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	l = b - a
	(x, y) = (m - r, m + r)
	if x <= b and a <= y:
		if a <= x and y <= b:
			print(l - (y - x))
		elif x <= a and b <= y:
			print(l - (b - a))
		elif x <= a and a <= y <= b:
			print(l - (y - a))
		elif a <= x <= b and b <= y:
			print(l - (b - x))
	else:
		print(l)


t = int(input())
for x in range(t):
	(a, b, c, r) = (int(x) for x in input().split())
	minc = c - r
	maxc = c + r
	count = 0
	dist = 0
	if a == b:
		print(0)
		continue
	if r == 0:
		print(abs(a - b))
		continue
	if a < b:
		if maxc <= a or minc >= b:
			print(abs(a - b))
			continue
		if minc < a:
			pass
		else:
			dist += minc - a
		if b < maxc:
			pass
		else:
			dist += b - maxc
	elif a > b:
		if minc >= a or maxc <= b:
			print(abs(a - b))
			continue
		if minc < b:
			pass
		else:
			dist += minc - b
		if maxc > a:
			pass
		else:
			dist += a - maxc
	print(dist)


import math as mt
import sys, string
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def main():
	(a, b, c, r) = M()
	if a > b:
		(a, b) = (b, a)
	print(b - a - max(min(c + r, b) - max(c - r, a), 0))
tc = 1
tc = I()
for _ in range(tc):
	main()


t = int(input())
while t > 0:
	(a, b, c, r) = [int(ele) for ele in input().split()]
	L = c - r
	R = c + r
	st = max(L, min(a, b))
	rt = min(R, max(a, b))
	print(abs(a - b) - max(0, rt - st))
	t -= 1


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	if a > b:
		(a, b) = (b, a)
	if left >= b or right <= a:
		print(b - a)
	elif left <= a <= b <= right:
		print(0)
	elif left <= a <= right <= b:
		print(b - right)
	elif a <= left <= b <= right:
		print(left - a)
	else:
		print(b - a + left - right)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	c1 = c + r
	c2 = c - r
	if b < a:
		(a, b) = (b, a)
	if c2 < c1:
		(c1, c2) = (c2, c1)
	d = 0
	if c1 >= b and c2 >= b:
		d = b - a
	elif c1 <= a and c2 <= a:
		d = b - a
	elif c1 >= a and c1 <= b and (c2 >= a) and (c2 <= b):
		d = abs(b - a) - abs(c1 - c2)
	elif c1 <= a and c2 <= b:
		d = abs(b - c2)
	elif c1 >= a and c1 <= b and (c2 >= b):
		d = abs(a - c1)
	print(d)


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(j) for j in input().split()]
	(a, b) = (min(a, b), max(a, b))
	if c + r <= a or c - r >= b:
		print(b - a)
	elif c <= a:
		x = min(c + r, b)
		print(b - x)
	elif c >= b:
		x = max(a, c - r)
		print(x - a)
	else:
		x1 = min(c + r, b)
		x2 = max(a, c - r)
		print(b - x1 + x2 - a)


for i in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	t = [a, b]
	if min(t) <= c <= max(t):
		(u, v) = [c - r, c + r]
		if u >= min(t) and v <= max(t):
			print(max(t) - min(t) - (v - u))
		elif u >= min(t) and v >= max(t):
			print(max(t) - min(t) - (max(t) - u))
		elif u <= min(t) and v <= max(t):
			print(max(t) - min(t) - (v - min(t)))
	elif c > max(t):
		(u, v) = [c - r, c + r]
		if min(t) <= u <= max(t):
			print(u - min(t))
		elif u > max(t):
			print(max(t) - min(t))
	elif c < min(t):
		(u, v) = [c - r, c + r]
		if max(t) >= v >= min(t):
			print(max(t) - v)
		elif v < min(t):
			print(max(t) - min(t))
	if c + r > max(t) and c - r < min(t):
		print(0)


import sys
t = int(sys.stdin.readline().strip())
for i in range(t):
	(a, b, c, r) = [int(x) for x in sys.stdin.readline().strip().split(' ')]
	cov_min = c - r
	cov_max = c + r
	uncov = None
	if a <= b:
		if cov_max <= a or cov_min >= b:
			uncov = b - a
		elif a <= cov_min:
			if b <= cov_max:
				uncov = cov_min - a
			else:
				uncov = b - cov_max + cov_min - a
		elif b <= cov_max:
			uncov = 0
		else:
			uncov = b - cov_max
	elif cov_max <= b or cov_min >= a:
		uncov = a - b
	elif b <= cov_min:
		if a <= cov_max:
			uncov = cov_min - b
		else:
			uncov = a - cov_max + cov_min - b
	elif a <= cov_max:
		uncov = 0
	else:
		uncov = a - cov_max
	print(uncov)


def swap(x, y):
	return (y, x)
t = int(input())
sol = []
while t > 0:
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = swap(a, b)
	if a <= c and c <= b:
		if c + r < b and c - r > a:
			ans = b - a - 2 * r
		elif c + r >= b and c - r > a:
			ans = c - a - r
		elif c + r < b and c - r <= a:
			ans = b - r - c
		elif c + r >= b and c - r <= a:
			ans = 0
	elif a > c:
		if c + r >= a and c + r <= b:
			ans = b - c - r
		elif c + r < a:
			ans = b - a
		elif c + r > b:
			ans = 0
	elif c > b:
		if c - r <= b and c - r >= a:
			ans = c - r - a
		elif c - r > b:
			ans = b - a
		elif c - r < a:
			ans = 0
	sol.append(ans)
	t -= 1
for i in range(len(sol)):
	print(sol[i])


import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
import math
from decimal import Decimal
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(a, b):
	c = []
	ans = 0
	f = int(math.sqrt(a))
	for i in range(1, f + 1):
		if a % i == 0:
			c.append(i)
	l = len(c)
	for i in range(l):
		c.append(a // c[i])
	for i in range(len(c)):
		if c[i] <= b:
			ans += 1
	if a / f == f and b >= f:
		return ans - 1
	return ans
for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if c - r <= a and c + r >= b:
		print(0)
		continue
	if c <= a:
		print(max(0, b - a - max(0, c + r - a)))
	elif c >= a and c <= b:
		d1 = c - r
		d2 = r + c
		if d1 <= a:
			ans1 = c - a
		else:
			ans1 = r
		if d2 <= b:
			ans2 = r
		else:
			ans2 = b - c
		print(max(0, b - a - ans1 - ans2))
	else:
		print(max(0, b - a - max(0, b - (c - r))))


for _ in range(int(input())):
	(a, b, c, r) = [int(i) for i in input().split()]
	if a > b:
		(b, a) = (a, b)
	s = min(max(a, c - r), b)
	e = max(min(b, c + r), a)
	dist = e - s
	print(b - a - dist)


for x in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	(mx, mn) = (c + d, c - d)
	if max(a, b) <= mn or min(a, b) >= mx:
		print(abs(a - b))
	elif mn <= min(a, b) and mx >= max(a, b):
		print(0)
	elif mn < max(a, b) < mx:
		print(abs(a - b) - max(a, b) + mn)
	elif mn >= min(a, b) and mx <= max(a, b):
		print(abs(a - b) - mx + mn)
	else:
		print(abs(a - b) - mx + min(a, b))


I = input
for x in range(int(I())):
	(a, b, c, d) = map(int, I().split())
	print(min(abs(a - b), max(0, abs(a - c) - d) + max(0, abs(b - c) - d)))


import sys
input = sys.stdin.readline
t = int(input())
while t > 0:
	(a, b, c, r) = map(int, input().split())
	if a > b:
		k = a
		a = b
		b = k
	d = c - r
	e = c + r
	ans = 0
	if a > e or b < d:
		ans = b - a
	elif a >= d and b <= e:
		ans = 0
	else:
		overlap = e - a + 1 if e <= b else b - d + 1
		if d >= a and e <= b:
			overlap = r * 2 + 1
		ans = b - a + 1 - overlap
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	pre = input().split()
	(a, b, c, r) = (int(pre[0]), int(pre[1]), int(pre[2]), int(pre[3]))
	(a, b) = (min(a, b), max(a, b))
	print(min(max(0, c - r - a), b - a) + min(max(0, b - (c + r)), b - a))


a = int(input())
for i in range(a):
	count = 0
	b = list(map(int, input().split(' ')))
	l = b[2] - b[3]
	u = b[2] + b[3]
	s = min(b[0], b[1])
	e = max(b[0], b[1])
	if l <= s <= e <= u:
		count = 0
	elif l <= s <= u <= e:
		count = e - u
	elif s <= l <= e <= u:
		count = l - s
	elif s <= l <= u <= e:
		count = e - u - s + l
	elif l <= u <= s <= e or s <= e <= l <= u:
		count = e - s
	print(count)


for _ in range(int(input())):
	(a, b, c, r) = tuple(map(int, input().split()))
	s = min((a, b))
	e = max((a, b))
	ans = e - s
	cs = c - r
	ce = c + r
	if ce <= s:
		print(max((ans, 0)))
		continue
	if cs <= s and ce >= s:
		print(max((0, ans - (ce - s))))
		continue
	if cs >= s and ce <= e:
		print(max((0, ans - (ce - cs))))
		continue
	if cs >= s and ce >= e and (cs < e):
		print(max(0, ans - (e - cs)))
		continue
	if cs >= s and ce >= e:
		print(max((0, ans)))


def temporarilyUnavailableSingle(a, b, c, r):
	minLimit = min(a, b)
	maxLimit = max(a, b)
	a = minLimit
	b = maxLimit
	diff = b - a
	first = c - r
	second = c + r
	temp1 = min(b, second)
	temp2 = max(a, first)
	possible = temp1 - temp2
	exclude = max(possible, 0)
	result = diff - exclude
	return result

def temporarilyUnavailable(givenInput):
	input = givenInput.split('\n')
	input = input[1:]
	result = ''
	for i in range(len(input)):
		singleLine = input[i]
		singleLine = singleLine.split()
		a = singleLine[0]
		b = singleLine[1]
		c = singleLine[2]
		r = singleLine[3]
		a = eval(a)
		b = eval(b)
		c = eval(c)
		r = eval(r)
		singleResult = temporarilyUnavailableSingle(a, b, c, r)
		if i < len(input) - 1:
			result = result + str(singleResult) + '\n'
		else:
			result = result + str(singleResult)
	print(result)
n = eval(input())
givenInput = str(n) + '\n'
for i in range(n):
	singleLine = input()
	if i == n - 1:
		givenInput += singleLine
		continue
	givenInput += singleLine + '\n'
temporarilyUnavailable(givenInput)


import os
import sys
from io import BytesIO, IOBase

def solution(a, b, c, r):
	(a, b) = sorted([a, b])
	if c + r <= a or c - r >= b:
		write(b - a)
	elif c - r <= a and c + r >= b:
		write(0)
	else:
		left = max(a, c - r)
		right = min(c + r, b)
		write(b - a - (right - left))

def main():
	for _ in range(r_int()):
		(a, b, c, r) = r_array()
		solution(a, b, c, r)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


import math
from collections import defaultdict
ml = lambda : map(int, input().split())
ll = lambda : list(map(int, input().split()))
ii = lambda : int(input())
ip = lambda : input()
t = ii()
for _ in range(t):
	(a, b, c, d) = ml()
	if a > b:
		(a, b) = (b, a)
	left = max(c - d, a)
	right = min(c + d, b)
	if left <= b and right >= a:
		print(b - a - (right - left))
	else:
		print(b - a)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	t = int(input())
	for _ in range(t):
		(a, b, c, r) = map(int, input().split())
		(a, b) = sorted([a, b])
		s = max(a, c - r)
		e = min(b, c + r)
		print(b - a - max(0, e - s))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t != 0:
	a = list(map(int, input().split(' ')))
	b = a.pop()
	c = a.pop()
	a.sort()
	d = c + b
	e = c - b
	count = 0
	if d > a[0] and d < a[1]:
		if c <= a[0]:
			count = count + abs(d - a[1])
		elif c >= a[0] and c < a[1]:
			count = count + abs(d - a[1])
	if e > a[0] and e < a[1]:
		if c >= a[1]:
			count = count + abs(e - a[0])
		elif c >= a[0] and c < a[1]:
			count = count + abs(e - a[0])
	if d <= a[0] and e <= a[0] or (d >= a[1] and e >= a[1]):
		count = count + abs(a[0] - a[1])
	if c <= a[0] and d >= a[1]:
		count = 0
	if c >= a[1] and e <= a[0]:
		count = 0
	print(count)
	t = t - 1


n = int(input())
for j in range(n):
	l = list(map(int, input().split()))
	low = l[2] - l[3]
	high = l[2] + l[3]
	a = []
	a.append(l[0])
	a.append(l[1])
	a.sort()
	countt = 0
	if low <= a[0] and high >= a[1]:
		print(0)
	elif low >= a[1] and high >= a[1] or (low <= a[0] and high <= a[0]):
		print(a[1] - a[0])
	elif low >= a[0] and high <= a[1]:
		print(a[1] - a[0] - (high - low))
	elif low >= a[0] and high >= a[1]:
		print(a[1] - a[0] - (a[1] - low))
	elif low <= a[0] and high <= a[1]:
		print(a[1] - a[0] - (high - a[0]))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	events = []
	events.append((c - r, 1))
	events.append((c + r, -1))
	events.append((a, 1))
	events.append((b, -1))
	events.sort()
	status = 0
	answer = 0
	prev = 0
	for (pos, val) in events:
		if status == 2:
			answer = pos - prev
		status += val
		prev = pos
	print(b - a - answer)


n = int(input())
for _ in range(n):
	(a, b, c, r) = list(map(int, input().split()))
	a1 = min(a, b)
	b1 = max(a, b)
	res = b1 - a1
	if a1 > c + r and b1 > c + r:
		print(res)
		continue
	if a1 < c - r and b1 < c - r:
		print(res)
		continue
	if b1 > c - r or a1 < c + r:
		res -= min(b1, c + r) - max(a1, c - r)
	print(res)


t = int(input())
for i in range(t):
	(A, B, c, r) = map(int, input().split())
	a = min(A, B)
	b = max(A, B)
	e = c - r
	f = c + r
	temp = b - a
	if e >= a and f <= b:
		temp = temp - 2 * r
		if temp < 0:
			print(0)
		else:
			print(temp)
	elif e <= a and f >= b:
		print(0)
	elif e <= a and f >= a:
		print(temp - (f - a))
	elif f >= b and e <= b:
		print(temp - (b - e))
	else:
		print(temp)


import sys
Input = sys.stdin.readline
for i in range(int(Input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(cl, cr) = (c - r, c + r)
	print(b - a - max(min(cr, b) - max(cl, a), 0))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		(b, a) = (a, b)
	mi = c - r
	ma = c + r
	if mi <= b and ma >= a:
		if mi < a:
			mi = a
		if ma > b:
			ma = b
		print(b - a - (ma - mi))
	else:
		print(b - a)


def res(a, b, c, r):
	if a > b:
		(a, b) = (b, a)
	way = b - a
	if r == 0:
		return way
	r1 = c - r
	r2 = c + r
	if r1 > b or r2 < a:
		return way
	return way - (min(b, r2) - max(a, r1))
for _ in range(int(input())):
	print(' ', res(*map(int, input().split())))


import sys
input = sys.stdin.readline
Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]
for (A, B, C, D) in Query:
	if A > B:
		(A, B) = (B, A)
	p1 = C - D
	p2 = C + D
	ans = 0
	if A <= p1 <= p2 <= B:
		ans = p1 - A + B - p2
	elif A > p2 or p1 > B:
		ans = B - A
	elif p1 <= A <= p2 <= B:
		ans = B - p2
	elif A <= p1 <= B <= p2:
		ans = p1 - A
	print(ans)


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	p1 = min(a, b)
	p2 = max(a, b)
	if r > abs(p1 - p2) and a <= c and (b >= c):
		print(0)
		continue
	if p1 >= c - r and p2 <= c or (p1 >= c and p2 <= c + r):
		print(0)
		continue
	if p1 >= c - r and p2 <= c + r:
		print(0)
		continue
	if c + r < p1 or p2 < c - r:
		print(abs(p1 - p2))
		continue
	if a == b and b == c:
		print(0)
		continue
	if a == c or b == c:
		print(abs(b - a) - r)
		continue
	if p1 >= c - r and p2 >= c + r:
		print(abs(p1 - p2) - (c - p1) - r)
		continue
	if p1 < c - r and p2 < c + r:
		print(abs(p1 - p2) - r - (p2 - c))
		continue
	if p1 <= c - r and p2 >= c + r:
		print(abs(p1 - p2) - 2 * r)
		continue
	print('uwu')


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(b, a) = (a, b)
	(c1, c2) = (c - r, c + r)
	c1_inside = a <= c1 and c1 <= b
	c2_inside = a <= c2 and c2 <= b
	if c1_inside:
		if c2_inside:
			print(c1 - a + b - c2)
		else:
			print(c1 - a)
	elif c2_inside:
		print(b - c2)
	elif c1 >= b or c2 <= a:
		print(b - a)
	else:
		print(0)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	ca = c - r
	cb = c + r
	d = 0
	if cb <= a or b <= ca:
		d = b - a
	elif ca <= a <= cb <= b:
		d = b - cb
	elif a <= ca <= b <= cb:
		d = ca - a
	elif ca <= a <= b <= cb:
		d = 0
	elif a <= ca <= cb <= b:
		d = ca - a + b - cb
	print(d)


for T in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	points = [(a, 1), (b, 1), (c - r, -1), (c + r, -1)]
	(available, on_trip, last) = (False, False, None)
	unavailable_minutes = 0
	for (position, type_) in sorted(points):
		if last is not None:
			minutes = position - last
			if on_trip and minutes > 0:
				if not available:
					unavailable_minutes += minutes
		last = position
		if type_ < 0:
			available = not available
		else:
			on_trip = not on_trip
	print(unavailable_minutes)


t = int(input())
while t:
	t = t - 1
	chars = input().split()
	a = int(chars[0])
	b = int(chars[1])
	if a > b:
		temp = a
		a = b
		b = temp
	c = int(chars[2])
	r = int(chars[3])
	ans = 0
	if a == b:
		print(0)
		continue
	if a < c - r and c - r <= b:
		ans = ans + (c - r - a)
	elif a < c - r and b < c - r:
		ans = b - a
		print(ans)
		continue
	if b > c + r and a <= c + r:
		ans = ans + (b - (c + r))
	elif b > c + r and a > c + r:
		ans = b - a
		print(ans)
		continue
	print(ans)


for i in range(int(input())):
	(d, f, c, r) = map(int, input().split())
	count = 0
	p = c - r
	q = c + r
	if d < f:
		a = d
		b = f
	else:
		a = f
		b = d
	if a < p and b < p:
		print(b - a)
	elif a < p and b <= q:
		print(p - a)
	elif a < p and b > q:
		print(p - a + b - q)
	elif a < q and b <= q:
		print(0)
	elif a < q and b > q:
		print(b - q)
	else:
		print(b - a)


def func(a, b, c, r):
	(a, b) = (min(a, b), max(a, b))
	if c <= a:
		sum = 0
		if c + r > a:
			sum = sum + c + r - a
			sum = min(sum, b - a)
	elif c > a and c <= b:
		sum = min(r, c - a)
		sum = sum + min(r, b - c)
	else:
		sum = 0
		if c - r < b:
			sum = sum + b - (c - r)
			sum = min(sum, b - a)
	return b - a - sum
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(a, b, c, r) = (l[0], l[1], l[2], l[3])
	print(func(a, b, c, r))


from sys import stdin, stdout
import bisect

def st():
	return list(stdin.readline().strip())

def inp():
	return int(stdin.readline())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def pr(n):
	stdout.write(str(n) + '\n')

def soe(limit):
	l = [1] * (limit + 1)
	prime = []
	for i in range(2, limit + 1):
		if l[i]:
			for j in range(i * i, limit + 1, i):
				l[j] = 0
	for i in range(2, limit + 1):
		if l[i]:
			prime.append(i)
	return prime

def segsoe(low, high):
	limit = int(high ** 0.5) + 1
	prime = soe(limit)
	n = high - low + 1
	l = [0] * (n + 1)
	for i in range(len(prime)):
		lowlimit = low // prime[i] * prime[i]
		if lowlimit < low:
			lowlimit += prime[i]
		if lowlimit == prime[i]:
			lowlimit += prime[i]
		for j in range(lowlimit, high + 1, prime[i]):
			l[j - low] = 1
	for i in range(low, high + 1):
		if not l[i - low]:
			if i != 1:
				print(i)

def power(a, n):
	r = 1
	while n:
		if n & 1:
			r = r * a
			n = n - 1
		else:
			a = a * a
			n = n >> 1
	return r

def solve():
	(a, b, c, r) = mp()
	z = abs(a - b)
	(x, y) = (min(a, b), max(a, b))
	h = max(c - r, x)
	g = min(c + r, y)
	print(z - max(0, g - h))
for _ in range(inp()):
	solve()


t = int(input())
while t != 0:
	t -= 1
	(a, b, c, r) = map(int, input().split())
	if a > b:
		temp = a
		a = b
		b = temp
	ans = 0
	if c >= a and c <= b:
		if c - r <= a:
			ans += 0
		else:
			ans += c - a - r
		if c + r >= b:
			ans += 0
		else:
			ans += b - c - r
	elif c <= a:
		if c + r <= a:
			ans = b - a
		elif c + r <= b:
			ans = b - (c + r)
		elif c + r >= b:
			ans = 0
	elif c - r >= b:
		ans = b - a
	elif c - r >= a:
		ans = c - r - a
	else:
		ans = 0
	print(ans)


for u in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ans = 0
	rr = r
	l = c - rr
	r = c + rr
	if r < a or l > b:
		print(b - a)
	elif r <= b and l >= a:
		print(b - a - 2 * rr)
	elif r <= b and l < a:
		print(b - r)
	elif r > b and l >= a:
		print(l - a)
	else:
		print(0)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	d = abs(a - b)
	(left, right) = (c - r, c + r)
	print(d - max(0, min(right, max(a, b)) - max(left, min(a, b))))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	x = abs(a - b)
	y = abs(a - c)
	z = abs(b - c)
	if y <= r and z <= r or x == 0:
		print(0)
	elif x == y + z:
		print(max(0, abs(y) - r) + max(0, abs(z) - r))
	elif x < y + z:
		if y > z:
			print(x - max(0, r - z))
		elif z > y:
			print(x - max(0, r - y))


def solve(a, b, c, r):
	if a > b:
		(a, b) = (b, a)
	x = c - r
	y = c + r
	print(b - a - max(0, min(b, y) - max(a, x)))
n = int(input())
for _ in range(n):
	(a, b, c, r) = list(map(int, input().strip().split()))
	solve(a, b, c, r)


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(a, b, c, r) = invr()
	if a > b:
		(a, b) = (b, a)
	L = c - r
	R = c + r
	ans = 0
	if L <= a and R >= b:
		ans = 0
	elif a >= R or b <= L:
		ans = b - a
	elif a <= L and b >= R:
		ans += b - a - (R - L)
	elif a <= L:
		ans += L - a
	elif b >= R:
		ans += b - R
	print(ans)


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	(a, b) = (min(a, b), max(a, b))
	cmin = c - r
	cmax = c + r
	left = max(cmin - a, 0)
	right = max(b - cmax, 0)
	ans = min(b - a, left + right)
	print(ans)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(l, ri) = (c - r, c + r)
	print(abs(b - a) - max(0, min(ri, max(a, b)) - max(l, min(a, b))))


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	(m, n) = (min(a, b), max(a, b))
	(a, b) = (m, n)
	d = c + r
	c = c - r
	if d < a or b < c:
		print(b - a)
	elif c <= a and d >= a and (d <= b):
		print(b - d)
	elif d >= b and c >= a and (c <= b):
		print(c - a)
	elif c <= a and d >= b:
		print(0)
	else:
		print(c - a + b - d)


def Input():
	tem = input().split()
	ans = []
	for it in tem:
		ans.append(int(it))
	return ans
T = Input()[0]
for t in range(T):
	(a, b, c, r) = Input()
	if a > b:
		(a, b) = (b, a)
	(c, d) = (c - r, c + r)
	tem = b - a
	if c > b or d < a:
		print(tem)
	elif a >= c and b <= d:
		print(0)
	elif a <= c and b >= d:
		print(tem - d + c)
	elif a >= c and b >= d:
		print(tem - d + a)
	else:
		print(tem - b + c)


def calcular(a, b, c, r):
	k = 0
	x1 = c - r
	x2 = c + r
	if a < x1:
		k += min(x1, b) - a
	if b > x2:
		k += b - max(x2, a)
	return k
teste = int(input())
for p in range(teste):
	entrada = input().split(' ')
	a = int(entrada[0])
	b = int(entrada[1])
	c = int(entrada[2])
	r = int(entrada[3])
	menor = min(a, b)
	maior = max(a, b)
	print(calcular(menor, maior, c, r))


t = int(input())
for x in range(t):
	p = input().split()
	p = [int(x) for x in p]
	a = min(p[0], p[1])
	b = max(p[0], p[1])
	c1 = p[2] - p[3]
	c2 = p[2] + p[3]
	out = b - a
	if c1 < b and c2 > a:
		out -= min(c2, b) - max(c1, a)
	print(out)


def f():
	(a, b, c, ra) = [int(s) for s in input().split()]
	if a > b:
		(a, b) = (b, a)
	if a == b:
		return 0
	if ra == 0:
		return b - a
	l = c - ra
	r = c + ra
	if l <= a:
		if r <= a:
			return b - a
		if r < b:
			return b - r
		else:
			return 0
	elif l < b:
		if r <= b:
			return b - r + l - a
		else:
			return l - a
	else:
		return b - a
t = int(input())
for i in range(t):
	print(f())


t = int(input())
for _ in range(t):
	(x, y, c, r) = map(int, input().split())
	end1 = c + r
	end2 = c - r
	maxx = 0
	minn = 0
	if x > y:
		a = x
		b = y
	else:
		a = y
		b = x
	if end1 > end2:
		maxx = end1
		minn = end2
	else:
		maxx = end2
		minn = end1
	if a == b:
		print(0)
	elif a >= maxx and b >= maxx:
		print(abs(a - b))
	elif maxx == minn:
		print(abs(a - b))
	elif a <= minn and b <= minn:
		print(abs(a - b))
	elif a <= maxx and b <= maxx and (a >= minn) and (b >= minn):
		print(0)
	elif a >= maxx and b <= maxx and (b >= minn):
		print(abs(a - maxx))
	elif b <= minn and a >= minn and (a <= maxx):
		print(abs(b - minn))
	elif a >= maxx and b <= minn:
		print(abs(a - b) - (maxx - minn))


n = int(input())
for rwere in range(n):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	wyn = b - a
	if c >= b:
		wyn -= min(b - a, max(0, r - (c - b)))
	if c < b and c > a:
		wyn -= min(b - c, r)
		wyn -= min(c - a, r)
	if c <= a:
		wyn -= min(b - a, max(0, r - (a - c)))
	print(wyn)


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	total = max(a, b) - min(a, b)
	(x, y) = (c - r, c + r)
	this = min(max(a, b), y) - max(min(a, b), x)
	if this <= 0:
		print(total)
	else:
		print(total - this)


import sys
input = sys.stdin.readline
t = int(input())
for testcases in range(t):
	(a, b, c, r) = map(int, input().split())
	MINC = c - r
	MAXC = c + r
	if a == b:
		print(0)
	elif a < b:
		if a <= c <= b:
			print(max(0, MINC - a) + max(0, b - MAXC))
		elif c < a:
			print(min(b - a, max(0, b - MAXC)))
		elif c > b:
			print(min(b - a, max(0, MINC - a)))
	elif a >= c >= b:
		print(max(0, MINC - b) + max(0, a - MAXC))
	elif c < b:
		print(min(a - b, max(0, a - MAXC)))
	elif c > a:
		print(min(a - b, max(0, MINC - b)))


t = int(input())
while t != 0:
	t -= 1
	(a, b, c, r) = map(int, input().split())
	p = c - r
	q = c + r
	ans = 0
	if a > b:
		(a, b) = (b, a)
	ans = b - a - max(0, min(b, q) - max(a, p))
	print(ans)


def sol(a, b, c, r):
	na = min(a, b)
	nb = max(a, b)
	a = na
	b = nb
	cstart = min(c - r, c + r)
	cend = max(c - r, c + r)
	if cend <= a or cstart >= b:
		return b - a
	if cstart >= a and cend <= b:
		return b - a - 2 * r
	if cstart <= a and cend >= b:
		return 0
	if cstart >= a and cend >= b:
		return b - a - (b - cstart)
	if cstart <= a and cend <= b:
		return b - a - (cend - a)
numTestCase = int(input())
for i in range(numTestCase):
	(a, b, c, r) = map(int, input().split())
	print(sol(a, b, c, r))


def temp_unav(arr):
	a = min(arr[0], arr[1])
	b = max(arr[0], arr[1])
	c = arr[2]
	r = arr[3]
	if a <= c <= b:
		if a <= c - r <= b and a <= c + r <= b:
			ans = b - a - 2 * r
		elif a <= c - r <= b:
			ans = b - a - (b - (c - r))
		elif a <= c + r <= b:
			ans = b - a - (c + r - a)
		elif c - r <= a and c + r >= b:
			ans = 0
	elif c < a:
		if c + r < a:
			ans = b - a
		elif c + r >= b:
			ans = 0
		elif c + r >= a:
			ans = b - a - (c + r - a)
	elif c > b:
		if c - r > b:
			ans = b - a
		elif c - r <= a:
			ans = 0
		elif c - r <= b:
			ans = b - a - (b - (c - r))
	return ans
t = int(input())
for _ in range(t):
	arr = list(map(int, input().split()))
	print(temp_unav(arr))


t = int(input())
while t:
	t += -1
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	a1 = c - r
	a2 = c + r
	if a < a1:
		if b < a2:
			print(min(a1, b) - a)
		else:
			print(a1 - a + b - a2)
	elif b <= a2:
		print(0)
	else:
		print(b - max(a, a2))


def solve(a, b, c, d):
	if a > b:
		temp = a
		a = b
		b = temp
	if c - d < a and c + d - 1 > b - 1:
		return 0
	elif c - d > b - 1 or c + d - 1 < a:
		return b - a
	elif a <= c - d and c + d - 1 > b - 1:
		return c - d - a
	elif b >= c + d - 1 and c - d < a:
		return b - 1 - (c + d - 1)
	else:
		return b - a - 2 * d
n = int(input())
for i in range(n):
	(a, b, c, d) = [int(x) for x in input().split()]
	result = solve(a, b, c, d)
	print(result)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	mx = max(a, b)
	mn = min(a, b)
	l = max(mn, c - r)
	r = min(mx, c + r)
	res = mx - mn - max(0, r - l)
	print(res)


for i in range(int(input())):
	(*a, c, r) = map(int, input().split())
	a.sort()
	print(a[1] - a[0] - max(min(c + r, a[1]) - max(c - r, a[0]), 0))


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


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	in_r = c + r
	in_l = c - r
	in_r = min(b, in_r)
	in_l = max(a, in_l)
	cur = b - a
	if in_l <= in_r:
		cur -= in_r - in_l
	print(cur)


def main():
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	t = abs(b - a)
	if a <= c <= b:
		if c - r <= a and c + r >= b:
			print(0)
		elif c - r >= a and c + r >= b:
			print(t - r - (b - c))
		elif c - r >= a and c + r <= b:
			print(t - 2 * r)
		else:
			print(t - r - (c - a))
	elif a <= b <= c:
		if b <= c - r:
			print(t)
		else:
			print(t - min(b - (c - r), t))
	elif c <= a <= b:
		if c + r <= a:
			print(t)
		else:
			print(t - min(c + r - a, t))
a = int(input())
for i in range(a):
	main()


from collections import Counter
import math
t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(e, v) = (a, b)
	a = min(e, v)
	b = max(e, v)
	q = c + r
	w = c - r
	cnt = 0
	if a > q:
		cnt = b - a
	elif b < w:
		cnt = b - a
	elif a < w or b > q:
		if a < w:
			cnt += w - a
		if b > q:
			cnt += b - q
	print(cnt)


t = input()
for _ in range(int(t)):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	x = int(s[2])
	r = int(s[3])
	diff = 0
	tp = 0
	if a > b:
		temp = b
		b = a
		a = temp
	l = b - a
	if x > b:
		if x - r < b:
			tp = l - (b - (x - r))
		else:
			tp = l - diff
	elif x < a:
		if x + r > a:
			tp = l - (x + r - a)
		else:
			tp = l - diff
	elif x == a or x == b:
		if l - r < 0:
			tp = 0
		else:
			tp = l - r
	else:
		tp = 0
		if x - r > a:
			tp += r
		else:
			tp += x - a
		if x + r < b:
			tp += r
		else:
			tp += b - x
		tp = l - tp
	if tp < 0:
		print(0)
	else:
		print(tp)


n = int(input())
for j in range(n):
	(a, b, c, r) = map(int, input().split())
	a_max = max(a, b)
	a_min = min(a, b)
	ctr = 0
	if c - r > max(a, b) or c + r < a_min:
		print(a_max - a_min)
	else:
		if c - r - a_min > 0:
			ctr = ctr + c - r - a_min
		if a_max - c - r > 0:
			ctr = ctr + a_max - c - r
		print(ctr)


n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	big = max(a, b)
	small = min(a, b)
	distance = 0
	if big <= left:
		distance = big - small
	elif small >= right:
		distance = big - small
	elif big > left and big <= right:
		if small > left:
			distance = 0
		else:
			distance = left - small
	elif big > right:
		if small > left:
			distance = big - right
		else:
			distance = big - right + left - small
	print(distance)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	a1 = min(a, b)
	b1 = max(a, b)
	a = a1
	b = b1
	if c - r > b or c + r < a:
		print(b - a)
	else:
		res = max(c - r - a, 0)
		res += max(b - (c + r), 0)
		print(res)


from collections import deque
t = int(input())
for test in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	min_c = c - r
	max_c = c + r
	if min_c >= b or max_c <= a:
		print(b - a)
	else:
		lo = max(min_c, a)
		hi = min(max_c, b)
		print(b - a - (hi - lo))


t = int(input())
for exp in range(t):
	[aa, bb, c, r] = list(map(int, input().split()))
	a = min(aa, bb)
	b = max(aa, bb)
	l = min(max(a, c - r), b)
	r = max(min(b, c + r), a)
	if r >= l:
		res = b - a - (r - l)
	else:
		res = b - a
	print(res)


for k in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	temp = min(a, b)
	b = max(a, b)
	a = temp
	if left > b or right < a:
		print(b - a)
	elif left < a and right > b:
		print(0)
	elif left < a:
		print(b - right)
	elif right > b:
		print(left - a)
	else:
		print(b - a - (right - left))


def solve(a, b, c, r):
	(a, b) = (min(a, b), max(a, b))
	x = c - r
	y = c + r
	(x, y) = (min(x, y), max(x, y))
	if y <= a or x >= b:
		return abs(a - b)
	elif x <= a:
		if y > b:
			return 0
		elif y < b:
			return b - y
		else:
			return 0
	elif y > b:
		return x - a
	elif y < b:
		return x - a + (b - y)
	else:
		return x - a

def main():
	for _ in range(int(input())):
		(a, b, c, r) = list(map(int, input().split()))
		print(solve(a, b, c, r))
main()


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
mod = 10 ** 9 + 7
INF = float('inf')

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(inp()):
	(a, b, c, r) = inpl()
	if b < a:
		(a, b) = (b, a)
	(x, y) = (c - r, c + r)
	if y < a or b < x:
		res = b - a
	elif a <= x:
		if b <= y:
			res = x - a
		else:
			res = x - a + b - y
	elif b <= y:
		res = 0
	else:
		res = b - y
	print(max(0, res))


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	c1 = c - r
	c2 = c + r
	if c1 <= min(a, b) and c2 >= max(a, b):
		print(0)
	elif min(a, b) < c1 and c2 < max(a, b):
		print(max(a, b) - min(a, b) - 2 * r)
	elif c1 <= min(a, b) and c2 < max(a, b):
		print(max(a, b) - max(c2, min(a, b)))
	elif c1 > min(a, b) and c2 >= max(a, b):
		print(min(c1, max(a, b)) - min(a, b))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	e = min(a, b)
	d = max(a, b)
	if e <= c and c <= d:
		print(max(c - e - r, 0) + max(d - c - r, 0))
	elif c > d:
		print(min(max(c - e - r, 0), d - e))
	else:
		print(min(max(d - c - r, 0), d - e))


import math
n = int(input())
test = []
for i in range(n):
	temp = input().split(' ')
	test.append([int(x) for x in temp])
for i in range(n):
	a = test[i][0]
	b = test[i][1]
	c = test[i][2]
	r = test[i][3]
	sx = c - r
	dx = c + r
	int1 = max(sx, min(a, b))
	int2 = min(dx, max(a, b))
	time = math.fabs(b - a) - max(0, int2 - int1)
	print(int(time))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if c + r >= b and c - r <= a:
		print('0')
		continue
	if c + r <= a or c - r >= b:
		print(b - a)
		continue
	if c - r >= a and c + r <= b:
		print(b - a - 2 * r)
		continue
	if c + r >= a and c - r <= a:
		print(b - a - (c + r - a))
		continue
	if c + r >= b and c - r <= b:
		print(b - a - (b - (c - r)))
		continue


test_cases = int(input())
soln = []
while test_cases != 0:
	(ac, bc, c, r) = [int(_) for _ in input().split(' ')]
	if ac < bc:
		a = ac
		b = bc
	else:
		a = bc
		b = ac
	left_pt = c - r
	right_pt = c + r
	ans = b - a - max(0, min(b, right_pt) - max(a, left_pt))
	soln.append(ans)
	test_cases -= 1
for x in soln:
	print(x)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	k = max(a, b)
	a = min(a, b)
	b = k
	l = c - r
	r = c + r
	if l <= a and r >= b:
		print(0)
	elif l <= a and r <= a or (l >= b and r >= b):
		print(b - a)
	elif l <= a and r <= b:
		print(b - r)
	elif l <= b and r >= b:
		print(l - a)
	else:
		print(abs(a - l) + abs(b - r))


T = int(input())
for _ in range(T):
	n = list(map(int, input().strip().split()))
	(a, b, c, r) = (min(n[0], n[1]), max(n[0], n[1]), n[2], n[3])
	L = max(min(a, b), c - r)
	R = min(max(a, b), c + r)
	print(max(a, b) - min(a, b) - max(0, R - L))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	total = b - a
	max_bound = c + r
	min_bound = c - r
	bound = 0
	if max_bound >= b and min_bound <= a:
		bound = total
	elif max_bound < a:
		bound = 0
	elif min_bound > b:
		bound = 0
	else:
		if min_bound < a:
			min_bound = a
		if max_bound > b:
			max_bound = b
		bound = max_bound - min_bound
	print(total - bound)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(a, b, c, r) = mp()
	x = c - r
	y = c + r
	if a > b:
		(b, a) = (a, b)
	if a <= x <= y <= b:
		print(b - y + x - a)
	elif x <= a <= y <= b:
		print(b - y)
	elif a <= x <= b <= y:
		print(x - a)
	elif x <= a <= b <= y:
		print(0)
	else:
		print(b - a)


import math
t = int(input())

def get_data():
	data = list(map(int, input().split()))
	return data

def runner(data):
	a = min(data[0], data[1])
	b = max(data[0], data[1])
	c = data[2]
	r = data[3]
	x_max = c + r
	x_min = c - r
	if x_max >= b and x_min <= a:
		return 0
	elif x_max <= b and x_min >= a:
		return b - a - 2 * r
	elif x_max <= a and x_min <= a:
		return b - a
	elif x_max >= b and x_min >= b:
		return b - a
	elif x_max >= b and x_min >= a:
		return x_min - a
	elif x_max <= b and x_min <= a:
		return b - x_max
while t:
	data = get_data()
	print(runner(data))
	t = t - 1


T = int(input())
for i in range(T):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		d1 = b
		d2 = a
	else:
		d1 = a
		d2 = b
	d = abs(b - a) + 1
	c1 = c - r
	c2 = c + r
	ct = 0
	if c2 < d1 or c1 > d2:
		ct = 0
	else:
		if c1 < d1:
			l1 = d1
			if c2 > d2:
				l2 = d2
			else:
				l2 = c2
		else:
			l1 = c1
			if c2 > d2:
				l2 = d2
			else:
				l2 = c2
		ct = l2 - l1 + 1
	if ct == 0:
		ct = 0
	else:
		ct = ct - 1
	if d == 1:
		print(0)
	else:
		print(d - 1 - ct)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(p, q) = (c - r, c + r)
	ans = 0
	if p <= a:
		ans = b - max(a, q)
	elif b >= p > a:
		ans = p - a
		ans += b - min(b, q)
	elif p > b:
		ans = b - a
	print(max(0, ans))


t = int(input())
for _ in range(t):
	ans = 0
	(a, b, c, r) = map(int, input().split())
	r1 = c - r
	r2 = r + c
	if a > b:
		(a, b) = (b, a)
	if a <= r1:
		ans += r1 - a
	if b >= r2:
		ans += b - r2
	print(min(b - a, ans))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	(l, h) = (c - r, c + r)
	if a > b:
		(a, b) = (b, a)
	l = max(0, min(h, b) - max(a, l) + 1)
	ans = b - a + 1 - l
	if l == 0:
		ans -= 1
	print(ans)


t = int(input())
for q in range(t):
	(a, b, c, d) = map(int, input().strip().split())
	x = c - d
	y = c + d
	sum = 0
	x = sum = max(min(a, b), x)
	y = sum = min(max(a, b), y)
	print(abs(b - a) - max(0, y - x))


k = int(input())
answers = []
while k > 0:
	data = list(map(int, input().split()))
	(a, b, c, r) = data
	if a < b:
		way_coords = [a, b]
	else:
		way_coords = [b, a]
	(r1, r2) = (c - r, c + r)
	(coord1, coord2) = way_coords
	if coord1 > r2 or coord2 < r1:
		result = abs(a - b)
	else:
		res1 = lambda : r1 - coord1 if r1 - coord1 > 0 else 0
		res2 = lambda : coord2 - r2 if coord2 - r2 > 0 else 0
		result = res1() + res2()
	answers.append(result)
	k -= 1
for ans in answers:
	print(ans)


def main(a, b, x, r):
	if x < b and x > a or (x > b and x < a):
		if x - r < min([a, b]):
			l = abs(max([a, b]) - x) - r
			l = 0 if l < 0 else l
			print(l)
		elif x + r > max([a, b]):
			l = abs(min([a, b]) - x) - r
			l = 0 if l < 0 else l
			print(l)
		else:
			left = abs(b - a) - 2 * r
			left = 0 if left < 0 else left
			print(left)
			return
	elif x >= b and x >= a:
		if x - r < b or x - r < a:
			l = abs(b - a) - (r - abs(x - max([b, a])))
			l = 0 if l < 0 else l
			print(l)
		else:
			print(abs(b - a))
	elif x <= b and x <= a:
		if x + r > min([b, a]):
			l = abs(b - a) - (r - abs(x - min([b, a])))
			l = 0 if l < 0 else l
			print(l)
		else:
			print(abs(b - a))

def runner():
	val = input()
	for i in range(int(val)):
		a = input()
		a = a.split(' ')
		main(int(a[0]), int(a[1]), int(a[2]), int(a[3]))
runner()


t = int(input())
for q in range(t):
	(a1, b1, c, r) = [int(i) for i in input().split()]
	a = min(a1, b1)
	b = max(a1, b1)
	dist = b - a
	if c <= a:
		rad = c + r
		if rad > a:
			dist = max(0, dist - (rad - a))
	elif a < c < b:
		rad = c - r
		rad2 = c + r
		dist = max(0, rad - a) + max(0, b - rad2)
	elif c >= b:
		rad = c - r
		if rad < b:
			dist = max(0, dist - (b - rad))
	print(dist)


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	(a, b, c, r) = map(int, stdin.readline().split())
	v = b - a
	ans = None
	if v == 0:
		ans = 0
	else:
		v = v // abs(v)
		(r1, r2) = (c - r, c + r)
		ans = min((b - a) * v, max(0, (c - a) * v - r) + max(0, (b - c) * v - r))
	stdout.write('{}\n'.format(ans))


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	(a, b, c, r) = mi()
	a1 = c + r
	a2 = c - r
	(a, b) = (max(a, b), min(a, b))
	(a1, a2) = (max(a1, a2), min(a1, a2))
	s1 = abs(b - a)
	if a >= a2 and a <= a1:
		s = 0
	elif a * a1 < 0:
		s = abs(a - a1)
	else:
		s = abs(a - a1)
	if b >= a2 and b <= a1:
		s += 0
	elif b * a2 < 0:
		s += abs(b - a2)
	else:
		s += abs(b - a2)
	print(min(s, s1))


t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(i) for i in input().split()]
	if a > b:
		(a, b) = (b, a)
	lg = b - a
	if c + r <= a or c - r >= b:
		print(lg)
		continue
	cx = max(a, c - r)
	cy = min(b, c + r)
	print(lg - (cy - cx))


import math

def count_mins(a, b, c, r):
	a_in = False
	b_in = False
	if c - r <= a <= c + r:
		a_in = True
	if c - r <= b <= c + r:
		b_in = True
	if b_in and a_in:
		return 0
	elif not (b_in or a_in):
		if abs(a - c) + abs(b - c) > abs(a - b):
			return abs(a - b)
		else:
			return abs(a - b) - 2 * r
	elif a_in:
		return abs(b - c) - r
	else:
		return abs(a - c) - r
useless = int(input())
for j in range(useless):
	numbers = [int(i) for i in input().split()]
	print(count_mins(numbers[0], numbers[1], numbers[2], numbers[3]))


from math import *
t = int(input())
while t > 0:
	t -= 1
	(a, b, c, r) = map(int, input().split(' '))
	if a > b:
		(a, b) = (b, a)
	temp = b - a
	ll = c - r
	ul = c + r
	if ll >= a and ul <= b:
		dia = 2 * r
	elif ul >= b and ll <= a:
		dia = temp
	elif ul <= a:
		dia = 0
	elif ll >= b:
		dia = 0
	elif ll <= a and ul >= a and (ul <= b):
		ll = a
		dia = ul - ll
	elif ul >= b and ll <= b and (ll >= a):
		ul = b
		dia = ul - ll
	print(temp - dia)


import sys
from math import gcd
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from bisect import bisect_right
from bisect import bisect_left
from sys import stdin, stdout
from collections import defaultdict, deque
from math import log2, ceil, floor
inp = lambda : int(input())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, input().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
Judge = 0
if Judge:
	sys.stdin = open('input.in', 'r')
for i in range(inp()):
	(A, B, c, r) = mulip()
	a = min(A, B)
	b = max(A, B)
	t = b - a
	if c <= a:
		if c + r <= a:
			print(t)
		elif c + r >= a and c + r <= b:
			print(b - (c + r))
		else:
			print(0)
	elif b <= c:
		if c - r >= b:
			print(t)
		elif c - r <= b and c - r >= a:
			print(c - r - a)
		else:
			print(0)
	else:
		ans = 0
		if c - r > a:
			ans += c - r - a
		if c + r < b:
			ans += b - c - r
		print(ans)


kl = int(input())
for l in range(kl):
	p = [int(i) for i in input().split()]
	a = min(p[0], p[1])
	b = max(p[0], p[1])
	tn = p[2] - p[3]
	tk = p[2] + p[3]
	if tn >= b or tk <= a:
		print(b - a)
	elif tn >= a:
		print(b - a - (min(b, tk) - tn))
	else:
		print(b - a - (min(b, tk) - a))


for _ in range(int(input())):
	(a, b, c, r) = (int(x) for x in input().strip().split())
	if a > b:
		t = a
		a = b
		b = t
	c1 = c - r
	c2 = c + r
	if b < c1:
		print(abs(b - a))
	elif a > c2:
		print(abs(b - a))
	elif a < c1 and b <= c2:
		print(abs(c1 - a))
	elif a < c1 and b > c2:
		print(abs(c1 - a) + abs(b - c2))
	elif a >= c1 and b <= c2:
		print('0')
	elif a >= c1 and b > c2:
		print(abs(b - c2))


fun = lambda x: 0 if x < 0 else x
for opo in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	print(min(abs(a - b), fun(abs(b - c) - r) + fun(abs(a - c) - r)))


t = int(input())
while t != 0:
	(a, b, c, x) = map(int, input().strip().split())
	if a > b:
		temp = a
		a = b
		b = temp
	l = c - x
	r = c + x
	sl = max(l, a)
	sr = min(r, b)
	res = b - a - max(0, sr - sl)
	print(res)
	t -= 1


tc = int(input())
for _ in range(tc):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	left = c - r
	right = r + c
	if left <= a and right >= b:
		print(0)
	elif a >= right:
		print(b - a)
	elif b <= left:
		print(abs(b - a))
	elif a <= left <= right <= b:
		print(left - a + b - right)
	elif a <= left and right >= b:
		print(left - a)
	elif a >= left and right <= b:
		print(b - right)


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().split(' ')))
	(min_x, max_x) = (c - r, c + r)
	if a > b:
		(b, a) = (a, b)
	print(b - a - (max(a, min(b, max_x)) - min(b, max(a, min_x))))


n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	a1 = a
	b1 = b
	a = min(a1, b1)
	b = max(a1, b1)
	t = 0
	c1 = c - r
	c2 = c + r
	if c1 >= a and c1 <= b:
		if c2 >= a and c2 <= b:
			t = 2 * r
		else:
			t = r + r - c2 + b
	elif c1 <= a and c2 >= b:
		t = b - a
	elif c2 >= a and c2 <= b:
		t = 2 * r + c1 - a
	print(max(0, b - a - t))


n = int(input())
sol = []
for i in range(0, n):
	(a, b, c, r) = map(int, input().split())
	lol1 = c - r
	lol2 = c + r
	x = max(lol1, min(a, b))
	y = min(lol2, max(a, b))
	soln = abs(b - a) - max(0, y - x)
	sol.append(soln)
for i in range(0, len(sol)):
	print(sol[i], '\r')


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	start = min(a, b)
	stop = max(a, b)
	num = 0
	x1 = c - r
	x2 = c + r
	if start <= x1 and x2 <= stop:
		res = abs(start - stop) - (x2 - x1)
	elif start >= x2 or stop <= x1:
		res = abs(start - stop)
	elif start >= x1 and stop <= x2:
		res = 0
	elif start < x2 and start > x1:
		res = abs(start - stop) - (x2 - start)
	elif stop > x1:
		res = abs(start - stop) - (stop - x1)
	print(res)


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split(' ')]
	total = 0
	area_min = c - r
	area_max = c + r
	if b < a:
		(a, b) = (b, a)
	if area_min > a:
		total += min(area_min - a, b - a)
	if area_max < b:
		total += min(b - a, b - area_max)
	print(total)


t = int(input())
for _ in range(t):
	(d, e, c, r) = map(int, input().split())
	(a, b) = (min(d, e), max(d, e))
	(left_limit, right_limit) = (c - r, c + r)
	if min(left_limit, a) == a:
		if max(b, right_limit) == b:
			print(left_limit - a + b - right_limit)
		else:
			print(min(left_limit, b) - a)
	elif max(b, right_limit) == b:
		print(b - max(right_limit, a))
	else:
		print(0)


import math
t = int(input())
case = []
for i in range(t):
	case.append(list(map(int, input().split())))
for i in range(len(case)):
	a = case[i][0]
	b = case[i][1]
	c = case[i][2]
	r = case[i][3]
	b1 = c - r
	b2 = c + r
	if r >= abs(a - c):
		d1 = 0
	else:
		d1 = min(abs(b1 - a), abs(b2 - a))
	if r >= abs(b - c):
		d2 = 0
	else:
		d2 = min(abs(b - b1), abs(b - b2))
	print(min(d1 + d2, abs(b - a)))


test = int(input())
while test > 0:
	(a, temp, c, r) = map(int, input().split(' '))
	r1 = c - r
	r2 = c + r
	sum1 = 0
	sum2 = 0
	if temp < a:
		b = a
		a = temp
	else:
		b = temp
	if a <= r1 <= b:
		sum1 = r1 - a
	if a <= r2 <= b:
		sum2 = b - r2
	if sum2 == 0 and sum1 == 0:
		sum1 = b - a
	sum = sum1 + sum2
	if r1 <= a and r2 >= b:
		sum = 0
	print(sum)
	test = test - 1


for i in range(int(input())):
	a = list(map(int, input().split()))
	if a[0] > a[1]:
		(a[0], a[1]) = (a[1], a[0])
	covp = a[2] + a[3]
	covn = a[2] - a[3]
	if covp <= a[1] and covn >= a[0]:
		print(a[1] - a[0] - (covp - covn))
	elif covp > a[1] and covn <= a[1] and (covn > a[0]):
		print(a[1] - a[0] - (a[1] - covn))
	elif covn < a[0] and covp >= a[0] and (covp < a[1]):
		print(a[1] - a[0] - (covp - a[0]))
	elif covn <= a[0] and covp >= a[1]:
		print(0)
	else:
		print(a[1] - a[0])


for _ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	left = max(min(a, b), c - d)
	right = min(max(a, b), c + d)
	print(max(a, b) - min(a, b) - max(0, right - left))


for x in range(int(input())):
	s = [int(o) for o in input().split()]
	ans = abs(s[1] - s[0])
	c = [s[0], s[1]]
	c.sort()
	d = [s[2] - s[3], s[2] + s[3]]
	if c[0] < d[0]:
		a = c
		b = d
	else:
		a = d
		b = c
	overlap = 0
	if a[1] >= b[0]:
		if b[1] <= a[1]:
			overlap = b[1] - b[0]
		else:
			overlap = a[1] - b[0]
	else:
		overlap = 0
	print(ans - overlap)


for _ in range(int(input())):
	(q, w, e, r) = map(int, input().split())
	ans = 0
	if q < w:
		(q, w) = (w, q)
	else:
		q = q
		w = w
	l = e - r
	r = e + r
	st = max(l, min(q, w))
	en = min(r, max(q, w))
	print(ans + abs(w - q) - max(0, en - st))


t = int(input())
for _ in range(t):
	exin = input()
	exin = list(map(int, exin.split(' ')))
	L = max(min(exin[0], exin[1]), exin[2] - exin[3])
	R = min(max(exin[0], exin[1]), exin[2] + exin[3])
	print(max(exin[0], exin[1]) - min(exin[0], exin[1]) - max(0, R - L))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(a2, b2) = (c - r, c + r)
	if a <= a2 <= b and a <= b2 <= b:
		print(b - a - (b2 - a2))
		continue
	if a <= a2 <= b:
		print(b - a - (b - a2))
		continue
	if a <= b2 <= b:
		print(b - a - (b2 - a))
		continue
	if b2 >= b and a2 <= a:
		print(0)
		continue
	print(b - a)


t = int(input())
while t:
	(a, b, c, r) = list(map(int, input().split()))
	left = c - r
	right = c + r
	x = max(left, min(a, b))
	y = min(right, max(a, b))
	res = abs(b - a) - max(0, y - x)
	print(res)
	t -= 1


t = int(input())
for x in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	if b < a:
		(a, b) = (b, a)
	p1 = c - r - a
	if p1 < 0:
		p1 = 0
	p2 = b - (c + r)
	if p2 < 0:
		p2 = 0
	if p1 + p2 > b - a:
		print(b - a)
	else:
		print(p1 + p2)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	(a, b, c, r) = get_int_list()
	total_dist = abs(b - a)
	left = min(a, b)
	right = max(a, b)
	dist = right - left
	left_network = c - r
	right_network = c + r
	flag = True
	if left_network < left:
		left_network = left
	elif left_network > right:
		left_network = right_network = 0
		flag = False
	if flag:
		if right_network < left:
			right_network = left_network = 0
		elif right_network > right:
			right_network = right
	unavailable_range = right_network - left_network
	print(dist - unavailable_range)


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
for _ in range(int(z())):
	(a, b, c, r) = map(int, z().split())
	(a, b) = (min(a, b), max(a, b))
	(s, p) = (c - r, c + r)
	t = max(a, s)
	t2 = min(b, p)
	if t > t2:
		t = t2
	print(b - a - t2 + t)


from sys import stdin, exit
from math import gcd
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
for _ in range(int(input())):
	(a, b, c, r) = mi()
	if a > b:
		(a, b) = (b, a)
	eb = min(b, c + r)
	ea = max(a, c - r)
	ea = min(ea, eb)
	print(b - a - (eb - ea))


t = int(input())
for x in range(t):
	(a, b, c, r) = map(int, input().split())
	(l1, r1) = (a, b)
	(l2, r2) = (c - r, c + r)
	(l1, r1) = sorted([l1, r1])
	if l1 <= l2 and r2 <= r1:
		print(r1 - l1 - (r2 - l2))
	elif l2 <= l1 and r1 <= r2:
		print(0)
	elif l2 <= r2 < l1 <= r1 or l1 <= r1 < l2 <= r2:
		print(r1 - l1)
	else:
		if r2 > r1:
			r1 = l2
		else:
			l1 = r2
		print(r1 - l1)


result = []
for i in range(int(input())):
	aa = [int(i) for i in input().split()]
	a = aa[0]
	b = aa[1]
	c = aa[2]
	r = aa[3]
	a1 = min(a, b)
	a2 = max(a, b)
	if c - r >= max(a, b) or c + r <= min(a, b):
		result.append(max(a, b) - min(a, b))
	else:
		count = 0
		if c - r >= a1 and c + r <= a2:
			count = a2 - c - r + (c - r - a1)
		elif c - r >= a1 and c + r > a2:
			count = c - r - a1
		elif c - r < a1 and c + r <= a2:
			count = a2 - c - r
		elif c - r < a1 and c + r > a2:
			count = 0
		result.append(count)
for i in result:
	print(abs(i))


t = int(input())
for kk in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	d = 0
	l = max(min(a, b), c - r)
	r = min(max(a, b), c + r)
	d = max(a, b) - min(a, b) - max(0, r - l)
	print(d)


def find_time(positions):
	positions = positions.split()
	point1 = int(positions[0])
	point2 = int(positions[1])
	base = int(positions[2])
	radius = int(positions[3])
	if point1 > point2:
		(point1, point2) = (point2, point1)
	min_pt = base - radius
	max_pt = base + radius
	if min_pt <= point1 and max_pt >= point2:
		return 0
	elif point1 <= min_pt <= point2 and point1 <= max_pt <= point2:
		return min_pt - point1 + (point2 - max_pt)
	elif min_pt <= point1 and point1 < max_pt < point2:
		return point2 - max_pt
	elif max_pt >= point2 and point1 < min_pt < point2:
		return min_pt - point1
	else:
		return point2 - point1

def main():
	num_of_tests = eval(input())
	for i in range(num_of_tests):
		positions = input()
		print(find_time(positions))
main()


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	(left, right) = (c - r, c + r)
	if left <= a and right >= b:
		print(0)
	elif left <= a and a <= right < b:
		print(b - right)
	elif b >= left > a and right >= b:
		print(left - a)
	elif right <= a or left >= b:
		print(b - a)
	else:
		print(b - a - (right - left))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	dif = abs(b - a)
	if b < a:
		temp = b
		b = a
		a = temp
	if c < a:
		dif = a - c
		if dif <= r:
			ans = r - dif
			ans = b - a - ans
		else:
			ans = b - a
	elif c > b:
		dif = c - b
		if dif <= r:
			ans = r - dif
			ans = b - a - ans
		else:
			ans = b - a
	else:
		ans = b - a
		dif = abs(b - c)
		if dif >= r:
			ans -= r
		else:
			ans -= dif
		dif = abs(c - a)
		if dif >= r:
			ans -= r
		else:
			ans -= dif
	if ans < 0:
		print(0)
	else:
		print(ans)


t = int(input())
for i in range(t):
	l = list(map(int, input().split()))
	a = min(l[0], l[1])
	b = max(l[0], l[1])
	c = l[2]
	r = l[3]
	xdi = 0
	ydi = 0
	ans = 0
	if c >= a and c <= b:
		x = c - r
		if x < a:
			xdi = 0
		else:
			xdi = x - a
		y = c + r
		if y > b:
			ydi = 0
		else:
			ydi = b - y
		ans = xdi + ydi
	elif c < a:
		x = c + r
		if x < a:
			ans = b - a
		elif x < b:
			ans = b - x
		else:
			ans = 0
	elif c > b:
		y = c - r
		if y > b:
			ans = b - a
		elif y > a:
			ans = y - a
		else:
			ans = 0
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, r) = input().split()
	a0 = min(int(a), int(b))
	b0 = max(int(a), int(b))
	c = int(c)
	r = int(r)
	a1 = min(c - r, c + r)
	b1 = max(c - r, c + r)
	if a1 >= b0 or b1 <= a0:
		ans = b0 - a0
	elif a1 >= a0 and b1 <= b0:
		ans = b0 - a0 - (b1 - a1)
	elif a1 >= a0 and b1 >= b0:
		ans = a1 - a0
	elif a1 <= a0 and b1 <= b0:
		ans = b0 - b1
	else:
		ans = 0
	print(abs(ans))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		t = a
		a = b
		b = t
	m = c - r
	n = c + r
	if m <= a:
		if n <= a:
			print(abs(b - a))
		elif a < n <= b:
			print(abs(b - n))
		elif n > b:
			print(0)
	elif m > a and m < b:
		if n > a and n <= b:
			print(abs(m - a) + abs(b - n))
		elif n > b:
			print(abs(m - a))
	elif m >= b:
		print(abs(b - a))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	t_1 = max(c - r, min(a, b))
	t_2 = min(c + r, max(a, b))
	print(abs(a - b) - max(0, t_2 - t_1))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	mxleft = c - r
	mxright = c + r
	rez = 0
	if mxleft in range(min(a, b), max(a, b) + 1) and mxright in range(min(a, b), max(a, b) + 1):
		rez += mxleft - min(a, b)
		rez += max(a, b) - mxright
		print(rez)
	elif mxleft in range(min(a, b), max(a, b) + 1) and mxright not in range(min(a, b), max(a, b) + 1):
		rez += mxleft - min(a, b)
		print(rez)
	elif mxleft not in range(min(a, b), max(a, b) + 1) and mxright in range(min(a, b), max(a, b) + 1):
		rez += max(a, b) - mxright
		print(rez)
	elif mxleft not in range(min(a, b), max(a, b) + 1) and mxright not in range(min(a, b), max(a, b) + 1):
		if mxleft < min(a, b) and mxright < min(a, b):
			print(max(a, b) - min(a, b))
		elif mxleft > max(a, b) and mxright > max(a, b):
			print(max(a, b) - min(a, b))
		else:
			print(0)


def unavailable(a_par, b_par, c, r):
	a = min(a_par, b_par)
	b = max(a_par, b_par)
	radio_range = [c - r, c + r]
	path_length = abs(b - a)
	radio_range.sort()
	if radio_range[0] <= a and radio_range[1] > a:
		return max(0, path_length - abs(radio_range[1] - a))
	elif radio_range[0] >= a and radio_range[1] <= b:
		return max(0, path_length - abs(radio_range[1] - radio_range[0]))
	elif radio_range[1] >= b and radio_range[0] < b:
		return max(0, path_length - abs(b - radio_range[0]))
	else:
		return path_length
n_cases = int(input())
cases = []
for i in range(0, n_cases):
	case = input().split(' ')
	for j in range(0, len(case)):
		case[j] = int(case[j])
	cases.append(case)
for i in range(0, len(cases)):
	print(unavailable(cases[i][0], cases[i][1], cases[i][2], cases[i][3]))


def numBtw(a, b):
	return b - a
T = int(input())
for i in range(T):
	(a, b, c, r) = map(int, input().split(' '))
	if a > b:
		(a, b) = (b, a)
	ans = 0
	if a <= c <= b:
		if a < c - r:
			ans = ans + numBtw(a, c - r)
		if c + r < b:
			ans = ans + numBtw(c + r, b)
		print(ans)
	elif c < a:
		if a <= c + r <= b:
			print(numBtw(c + r, b))
		elif c + r < a:
			print(numBtw(a, b))
		elif b < c + r:
			print(0)
	elif b < c:
		if a <= c - r <= b:
			print(numBtw(a, c - r))
		elif c - r < a:
			print(0)
		elif b < c - r:
			print(numBtw(a, b))


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	dis = abs(b - a)
	if c > a and c > b or (c < a and c < b):
		z = min(abs(c - a), abs(c - b))
		if z >= r:
			print(dis)
		elif z < r:
			if dis + z - r < 0:
				print(0)
			else:
				print(dis + z - r)
	elif c > a and c < b or (c < a and c > b):
		z = min(abs(c - a), abs(c - b))
		if r >= max(abs(c - a), abs(c - b)):
			print(0)
		elif r > z and r < max(abs(c - a), abs(c - b)):
			print(max(abs(c - a), abs(c - b)) - r)
		elif r <= z:
			print(dis - 2 * r)
	elif c == a or c == b:
		ans = dis - r
		if ans < 0:
			print(0)
		else:
			print(ans)


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


q = int(input())

def per(a, b, c, d):
	if a <= c <= b or a <= d <= b or c <= a <= d or (c <= b <= d):
		return min(b, d) - max(a, c)
	return 0
for _ in range(q):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	print(b - a - per(a, b, c - r, c + r))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().strip().split())
	arr = [a, b]
	arr = sorted(arr)
	a = arr[0]
	b = arr[1]
	x = c - r
	y = c + r
	flg = -1
	if a >= x and b <= y:
		ans = b - a
		flg = 1
	elif a <= x and b >= y:
		ans = y - x
		flg = 2
	elif a <= x and b >= x and (b < y):
		ans = b - x
		flg = 3
	elif a <= y and b >= y and (a > x):
		ans = y - a
		flg = 4
	else:
		ans = 0
	print(b - a - ans)


t = int(input())
while t:
	l = list(map(int, input().split()))
	a = max(min(l[0], l[1]), l[2] - l[3])
	b = min(max(l[0], l[1]), l[2] + l[3])
	k = max(l[0], l[1]) - min(l[0], l[1]) - max(0, b - a)
	print(k)
	t -= 1


for _ in range(int(input().strip())):
	[a, b, c, r] = map(int, input().strip().split())
	if a >= b:
		(a, b) = (b, a)
	m = b - a
	ca = c - r
	cb = c + r
	if cb >= b:
		if ca <= a:
			print(0)
		elif ca <= b:
			print(ca - a)
		else:
			print(m)
	elif cb <= a:
		print(m)
	elif ca >= a:
		print(m - (cb - ca))
	else:
		print(m - (cb - a))


n = int(input())

def relu(p):
	if p <= 0:
		return 0
	else:
		return p
for i in range(n):
	(a, b, c, r) = list(map(int, input().split()))
	if c <= a <= b or b <= a <= c:
		print(relu(abs(a - b) - relu(r - abs(c - a))))
	elif a <= b <= c or c <= b <= a:
		print(relu(abs(a - b) - relu(r - abs(c - b))))
	else:
		print(relu(abs(c - a) - r) + relu(abs(c - b) - r))


for _ in range(int(input())):
	(p, q, c, r) = map(int, input().split())
	a = min(p, q)
	b = max(p, q)
	lc = c - r
	lr = c + r
	if a >= lc and b <= lr:
		ans = 0
	elif a > lr or b < lc:
		ans = abs(b - a)
	else:
		left = lc - a
		if left < 0:
			left = 0
		right = b - lr
		if right < 0:
			right = 0
		ans = left + right
	print(ans)


test = eval(input())
words = []
for i in range(test):
	word = input()
	words.append(word)
ans = []
for word in words:
	lst = word.split(' ')
	a = int(lst[0])
	b = int(lst[1])
	c = int(lst[2])
	r = int(lst[3])
	if a > b:
		(a, b) = (b, a)
	tot = 0
	l = c - r
	u = c + r
	if a < l:
		if b < l:
			tot += b - a
		else:
			tot += l - a
	if u < b:
		if a > u:
			tot = b - a
		else:
			tot += b - u
	ans.append(tot)
for i in ans:
	print(i)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
input = stdin.readline
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))
I = lambda : int(input())
S = lambda : input().strip()
for i in range(I()):
	(a, b, c, r) = li()
	(a, b) = (min(a, b), max(a, b))
	l = min(b, max(a, c - r))
	r = max(a, min(b, c + r))
	print(b - a - (r - l))


cases = int(input())
while cases:
	cases -= 1
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	pot = b - a
	cl = c - r
	cr = c + r
	if a <= cl <= cr <= b:
		ans = b - a - (cr - cl)
	elif cl <= a <= cr <= b:
		ans = b - cr
	elif a <= cl <= b <= cr:
		ans = cl - a
	elif cl <= a <= b <= cr:
		ans = 0
	else:
		ans = b - a
	print(ans)


T = int(input())
for t in range(1, T + 1):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	cm = c - r
	cp = c + r
	if cm > b or a > cp:
		print(b - a)
	else:
		print(-2 * r + (max(b, c + r) - min(a, c - r)))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ca = c - r
	cb = c + r
	cover = max(0, min(b, cb) - max(a, ca))
	print(b - a - cover)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(mir, mxr) = (c - r, c + r)
	ans = 0
	if c == a:
		if mxr >= b:
			ans = 0
		elif c + r < b:
			ans = b - mxr
	elif c == b:
		if mir <= a:
			ans = 0
		elif mir > a:
			ans = mir - a
	elif c > a and c < b:
		ans = mir - a if mir - a > 0 else 0
		ans += b - mxr if b - mxr > 0 else 0
	elif c < a:
		ans = b - mxr if b - mxr > 0 else 0
	elif c > b:
		ans = mir - a if mir - a > 0 else 0
	if ans > b - a:
		ans = b - a
	print(ans)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	minr = c - r
	maxr = c + r
	ans = 0
	(b, a) = (max(a, b), min(a, b))
	if a >= minr and b <= maxr:
		print('0')
	else:
		if a < minr:
			ans += minr - a
			if b < minr:
				ans = b - a
			elif b <= maxr and b >= minr:
				ans = minr - a
			elif b > maxr:
				ans = minr - a + b - maxr
		elif a > maxr:
			ans = b - a
		elif a >= minr:
			if b <= maxr:
				ans = 0
			if b > maxr:
				ans = b - maxr
		print(ans)


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

def main():
	N = int(input())
	for i in range(N):
		(a, b, c, r) = getlist()
		(a, b) = sorted([a, b])
		ans = 0
		if a <= c - r <= b:
			ans += c - r - a
		elif c - r > b:
			ans = b - a
		else:
			pass
		if a <= c + r <= b:
			ans += b - c - r
		elif c + r < a:
			ans = b - a
		else:
			pass
		print(ans)
main()


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	k1 = min(a, b)
	k2 = max(a, b)
	t = r
	g1 = c - r
	g2 = c + r
	if k1 >= g1 and k1 >= g2:
		print(k2 - k1)
	elif k1 >= g1 and k1 < g2:
		if k2 >= g2:
			print(k2 - g2)
		elif g2 >= k2:
			print(0)
	elif k1 <= g1 and g2 <= k2:
		print(g1 - k1 + k2 - g2)
	elif k2 > g1 and k2 < g2:
		print(g1 - k1)
	elif k2 <= g1:
		print(k2 - k1)


for _ in range(int(input())):
	(a1, b1, c, r) = map(int, input().split())
	a = min(a1, b1)
	b = max(a1, b1)
	e1 = c + r
	e2 = c - r
	if e1 <= b and e1 >= a and (e2 <= b) and (e2 >= a):
		val = b - a - 2 * r
	elif e1 >= b and e2 <= b and (e2 >= a):
		val = e2 - a
	elif e2 <= a and e1 >= a and (e1 <= b):
		val = b - e1
	elif e1 >= b and e2 >= b:
		val = b - a
	elif e1 <= a and e2 <= a:
		val = b - a
	elif e1 >= b and e2 <= a:
		val = 0
	if val > 0:
		print(val)
	else:
		print(0)


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write

def ii():
	return int(readline())

def mi():
	return map(int, readline().rstrip().split())

def li():
	return list(readline().rstrip())

def lmi():
	return list(map(int, readline().rstrip().split()))

def end(*arg):
	print(*arg)
	sys.exit()

def main():
	t = ii()
	for _ in range(t):
		(a, b, c, r) = mi()
		if a > b:
			(a, b) = (b, a)
		right = min(b, c + r)
		left = max(a, c - r)
		print(b - a - max(0, right - left))
	return
main()


for i in range(int(input())):
	l = list(map(int, input().split()))
	(a, b, c, r) = (min(l[0], l[1]), max(l[0], l[1]), l[2], l[3])
	if c - r >= a and c + r <= b:
		print(c - r - a + b - c - r)
	elif c - r <= a and c + r >= b:
		print(0)
	elif c - r < a and (c + r <= b and c + r >= a):
		print(b - c - r)
	elif c - r >= a and (c + r > b and c - r <= b):
		print(c - r - a)
	else:
		print(b - a)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if b < c - r or a > c + r:
		print(b - a)
	else:
		anc = c - r - a
		anc2 = b - c - r
		if anc < 0:
			anc = 0
		if anc2 < 0:
			anc2 = 0
		answ = anc + anc2
		print(answ)


num_t = int(input())

def intersection(r1, r2):
	(r1_start, r1_end) = r1
	(r2_start, r2_end) = r2
	return max(0, min(r1_end, r2_end) - max(r1_start, r2_start))
for t in range(num_t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	print(b - a - intersection((a, b), (c - r, c + r)))


t = int(input())
for i in range(t):
	(a, b, c, d) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(u, v) = (c - d, c + d)
	if a > v and b > v:
		print(abs(a - b))
	elif a < u and b < u:
		print(abs(a - b))
	else:
		ans = 0
		ans += max(u - a, 0)
		ans += max(b - v, 0)
		print(ans)


for _ in [0] * int(input()):
	(*a, c, r) = map(int, input().split())
	a = sorted(a)
	b = (c - r, c + r)
	d = a[1] - a[0]
	k = min(d, max(0, b[1] - a[0])) if b[0] < a[0] else max(0, min(b[1], a[1]) - b[0])
	print(d - k)


n = int(input())
for i in range(n):
	arr = [int(m) for m in input().split()]
	(a, b) = sorted(arr[:2])
	(tower, radius) = arr[2:4]
	if tower + radius < a or tower - radius > b:
		print(b - a)
		continue
	elif tower <= a:
		cover = max(a, min(tower + radius, b)) - a
		print(b - a - cover)
	elif a < tower < b:
		coverLeft = min(abs(tower - a), radius)
		coverRight = min(abs(b - tower), radius)
		print(b - a - coverLeft - coverRight)
	elif tower >= b:
		cover = min(radius - (tower - b), b - a)
		print(b - a - cover)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	l = c - r
	r = c + r
	st = max(l, min(a, b))
	ed = min(r, max(a, b))
	res = abs(a - b) - max(0, ed - st)
	print(res)


t = int(input())
for q in range(t):
	(a, b, c, r) = map(int, input().split(' '))
	(a, b) = (min(a, b), max(a, b))
	(left, right) = (c - r, c + r)
	if a >= left and b <= right:
		print(0)
	elif left > b or right < a:
		print(b - a)
	elif left >= a and left <= b and (right >= a) and (right <= b):
		print(b - a - (right - left))
	elif left <= a and (right >= a and right <= b):
		print(b - right)
	elif right >= b and (left >= a and left <= b):
		print(left - a)


n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	m = max(a, b)
	p = min(a, b)
	d = c - r
	e = c + r
	if a == b:
		print(0)
	elif d >= p and e <= m:
		print(abs(m - p - 2 * r))
	elif d >= m and e >= m or (p >= d and p >= e):
		print(abs(m - p))
	elif p >= d and e >= m:
		print(0)
	elif p >= d and m >= e:
		print(abs(m - p - (e - p)))
	elif d >= p and e >= m:
		print(abs(m - p - (m - d)))


T = int(input())
while T != 0:
	T -= 1
	(a, b, c, r) = map(int, input().split())
	L = c - r
	R = c + r
	if a > b:
		lins = a
		a = b
		b = lins
	ans = max(0, L - a)
	ans += max(0, b - R)
	ans = min(b - a, ans)
	print(ans)


for i in range(int(input())):
	X = list(map(int, input().split()))
	(X[0], X[1]) = (min(X[0], X[1]), max(X[0], X[1]))
	Sum = X[1] - X[0]
	Sum -= max(0, min(X[2] + X[3], X[1]) - max(X[0], X[2] - X[3]))
	print(Sum)


t = int(input())
answers = []
for i in range(t):
	s = input()
	ints = list(map(int, s.split()))
	(a, b, c, r) = (ints[0], ints[1], ints[2], ints[3])
	if a > b:
		(a, b) = (b, a)
	trip = abs(b - a)
	if c <= a:
		if c + r < a:
			answers.append(trip)
		elif a <= c + r <= b:
			answers.append(b - (c + r))
		else:
			answers.append(0)
	elif a < c < b:
		r1 = c - r
		r2 = c + r
		aa = c - a
		bb = b - c
		out = trip
		if aa <= r:
			out -= aa
		else:
			out -= r
		if bb <= r:
			out -= bb
		else:
			out -= r
		answers.append(out)
	elif c >= b:
		if c - r < a:
			answers.append(0)
		elif a <= c - r <= b:
			answers.append(c - r - a)
		else:
			answers.append(trip)
for a in answers:
	print(a)


t = int(input())
for i in range(0, t):
	inp = input()
	nums = [int(a) for a in inp.split()]
	a = nums[0]
	b = nums[1]
	c = nums[2]
	r = nums[3]
	(a, b) = (min(a, b), max(a, b))
	if b < c - r or a > c + r:
		print(b - a)
	else:
		alpha = max(c - r - a, 0)
		beta = max(b - c - r, 0)
		print(alpha + beta)


def solve():
	(tmpa, tmpb, c, r) = map(int, input().split())
	a = min(tmpa, tmpb)
	b = max(tmpa, tmpb)
	d = c - r
	e = c + r
	tmp = min(e, b) - max(a, d)
	tmp = tmp if tmp > 0 else 0
	print(b - a - tmp)
T = int(input())
for _ in range(T):
	solve()


t = int(input().strip())
for i in range(t):
	(a, b, c, r) = map(int, input().strip().split())
	len1 = abs(a - b)
	len2 = 2 * r
	x1 = c - r
	x2 = c + r
	left = min(a, b)
	right = max(a, b)
	if right <= x1 or left >= x2:
		print(len1)
	elif x1 <= left and x2 >= right:
		print(0)
	elif left <= x1 and right >= x2:
		print(len1 - len2)
	else:
		y1 = max(left, x1)
		y2 = min(right, x2)
		print(len1 - abs(y1 - y2))


def fn(a, b, c, r):
	x1 = min(a, b)
	y1 = max(a, b)
	x2 = c - r
	y2 = c + r
	if x1 >= x2 and y1 <= y2:
		return 0
	if x1 < x2 and y1 < y2 and (y1 > x2):
		return x2 - x1
	if y1 > y2 and x1 > x2 and (x1 < y2):
		return y1 - y2
	if x1 <= x2 and y1 >= y2:
		return y1 - x1 - (y2 - x2)
	return y1 - x1
t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	print(fn(a, b, c, r))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		temp = a
		a = b
		b = temp
	ll = c - r
	rr = c + r
	if ll <= a and rr <= a or (ll >= b and rr >= b):
		print(b - a)
	elif ll <= a and rr >= a and (rr <= b):
		print(b - rr)
	elif ll >= a and ll <= b and (rr >= b):
		print(ll - a)
	elif ll <= a and rr >= b:
		print('0')
	else:
		print(b - a - (rr - ll))


from operator import itemgetter
t = int(input())

def solve(a, b, c, r):
	left = c - r
	right = c + r
	if b <= left or a >= right:
		print(b - a)
	elif left <= a and b <= right:
		print(0)
	elif a <= left and right <= b:
		print(b - a - (right - left))
	elif left <= a:
		print(b - right)
	else:
		print(left - a)
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	solve(a, b, c, r)


res = []
for t in range(int(input())):
	(a, b, c, r) = list(map(int, input().split(' ')))
	left_cov = c - r
	right_cov = c + r
	min_dist = min(a, b)
	max_dist = max(a, b)
	m = max(left_cov, min_dist)
	n = min(right_cov, max_dist)
	diff_dist = n - m
	res.append(abs(a - b) - max(0, diff_dist))
for x in res:
	print(x)


test = int(input())
for i in range(test):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(x, y) = (min(max(c - r, a), b), max(min(c + r, b), a))
	ans = b - a - (y - x)
	print(ans)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	r1 = c - r
	r2 = c + r
	a1 = a
	b1 = b
	a = min(a1, b1)
	b = max(a1, b1)
	ans = 0
	if r1 <= b and r2 >= b:
		if r1 >= a:
			ans = r1 - a
		else:
			ans = 0
	elif r2 < b and r2 >= a:
		ans += b - r2
		if r1 >= a:
			ans += r1 - a
		else:
			ans += 0
	elif r2 < a:
		ans += b - a
	elif r1 > b:
		ans += b - a
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tt in range(t):
	(a, b, c, r) = [int(x) for x in input().strip().split()]
	(a, b) = (min(a, b), max(a, b))
	if r == 0:
		print(b - a)
		continue
	if c <= a:
		if c + r < a:
			print(b - a)
			continue
		elif c + r < b:
			print(b - (c + r))
			continue
		else:
			print(0)
			continue
	elif a < c < b:
		ans = 0
		if c - r > a:
			ans += c - r - a
		if c + r < b:
			ans += b - (c + r)
		print(ans)
		continue
	elif c - r > b:
		print(b - a)
		continue
	elif c - r > a:
		print(c - r - a)
		continue
	else:
		print(0)
		continue


for _ in range(int(input())):
	(aa, bb, c, r) = map(int, input().split())
	a = min(aa, bb)
	b = max(aa, bb)
	x = c - r
	y = c + r
	if y <= a or x >= b:
		print(abs(a - b))
	elif x <= a and a <= y <= b:
		print(abs(b - y))
	elif a <= x <= b and y >= b:
		print(abs(a - x))
	elif x <= a and y >= b:
		print(0)
	else:
		print(abs(a - b) - abs(x - y))


T = int(input())
for _ in range(T):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	c1 = c - r
	c2 = c + r
	overlap = max(0, min(b, c2) - max(a, c1))
	print(b - a - overlap)


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	c1 = c - d
	c2 = c + d
	(a, b) = (min(a, b), max(a, b))
	if a >= c2:
		print(b - a)
	elif b <= c1:
		print(b - a)
	else:
		print(b - a - min(b, c2) + max(a, c1))


from itertools import groupby
t = int(input())
for _ in range(t):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	c1 = c - d
	c2 = c + d
	res = 0
	if a < c1:
		if b <= c1:
			res += b - a
		else:
			res += c1 - a
	if c2 < b:
		if a >= c2:
			res += b - a
		else:
			res += b - c2
	print(res)


def solve():
	(a, b, c, r) = map(int, input().split())
	if a > b:
		t = a
		a = b
		b = t
	dis = b - a
	if a <= c <= b:
		dis -= min(r, c - a)
		dis -= min(r, b - c)
	elif c <= a:
		r = max(0, r - (a - c))
		dis -= min(r, b - a)
	else:
		r = max(0, r - (c - b))
		dis -= min(r, b - a)
	print(dis)
test = 1
test = int(input())
for i in range(test):
	solve()


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		d = a
		a = b
		b = d
	if c in range(a, b + 1):
		d1 = c - r - a
		d2 = b - (c + r)
		if d2 < 0:
			d2 = 0
		if d1 < 0:
			d1 = 0
		d = d1 + d2
	elif c > b:
		if c - r in range(a, b + 1):
			d = c - r - a
		elif c - r > b:
			d = b - a
		else:
			d = 0
	elif c + r in range(a, b + 1):
		d = b - (c + r)
	elif c + r < a:
		d = b - a
	else:
		d = 0
	print(d)


tt = int(input())
while tt:
	str = input()
	strings = str.split()
	a = int(strings[0])
	b = int(strings[1])
	c = int(strings[2])
	d = int(strings[3])
	if a > b:
		temp = a
		a = b
		b = temp
	total_time = b - a
	left = c - d
	right = c + d
	if left < a:
		left = a
	if right > b:
		right = b
	available_time = right - left
	if available_time < 0:
		available_time = 0
	print(total_time - available_time)
	tt -= 1


t = int(input())
for zz in range(t):
	(a, b, c, r) = map(int, input().split())
	d1 = max(0, abs(c - a) - r)
	d2 = max(0, abs(c - b) - r)
	print(min(d1 + d2, abs(b - a)))


n = int(input())
for i in range(n):
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(b, a) = (a, b)
	(lr, rr) = (c - r, c + r)
	if a <= c <= b:
		print(max(b - rr, 0) + max(lr - a, 0))
	elif c < a and rr > a:
		print(max(0, b - rr))
	elif c > b and lr < b:
		print(max(0, lr - a))
	else:
		print(b - a)


t = int(input())
for v in range(t):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	d = c - r
	e = c + r
	ans = 0
	if a <= e <= b and d <= a:
		ans = b - e
	if a <= d <= b and b <= e:
		ans = d - a
	if a < d < b and a < e < b:
		ans = b - e + d - a
	if a >= d and b <= e:
		ans = 0
	if e >= b and d >= b or (e <= a and d <= a):
		ans = b - a
	print(ans)


for _ in [0] * int(input()):
	(*t, c, r) = map(int, input().split())
	(a, b) = sorted(t)
	if c < a:
		r = max(0, b - max(a, c + r))
	elif c > b:
		r = max(0, min(b, c - r) - a)
	else:
		r = max(0, c - a - r) + max(0, b - c - r)
	print(r)


for _ in range(int(input())):
	(L, G, c, r) = map(int, input().split())
	if L == G:
		print(0)
		continue
	a = min(L, G)
	b = max(L, G)
	k1 = c - r
	k2 = c + r
	l = a
	d = b - a
	if r == 0:
		print(d)
		continue
	if c <= b and c >= a:
		if a <= k1 and b >= k2:
			d -= r * 2
		if a <= k1 and b < k2:
			d = k1 - a
		if a >= k1 and b >= k2:
			d = b - k2
		if a >= k1 and b < k2:
			d = 0
	else:
		if k2 <= a or k1 >= b:
			d = b - a
			print(d)
			continue
		if c < a:
			if k2 < b:
				d = b - k2
			if k2 >= b:
				d = 0
		if c > b:
			if k1 <= a:
				d = 0
			if k1 > a:
				d = k1 - a
	print(d)


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	ans = 0
	left = c - r
	right = c + r
	left_m = min(left, right)
	right_m = max(left, right)
	a_m = min(a, b)
	b_m = max(a, b)
	if left_m <= a_m <= right_m:
		r = 0
	elif left_m > a_m:
		ans += abs(left_m - a_m)
	if left_m <= b_m <= right_m:
		r = 0
	elif right_m < b_m:
		ans += abs(right_m - b_m)
	if left_m > b_m or right_m < a_m:
		ans = abs(a_m - b_m)
	print(ans)


def inp():
	return list(map(int, input().split()))
for tc in range(int(input())):
	(a, b, c, d) = inp()
	(a, b) = (min(a, b), max(a, b))
	x = c - d
	y = c + d
	ove = max(0, min(b, y) - max(a, x))
	print(b - a - ove)


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	l = b - a
	if c <= a:
		k = max(r - (a - c), 0)
		print(max(0, l - k))
	elif c >= b:
		k = max(r - (c - b), 0)
		print(max(0, l - k))
	else:
		k1 = max(c - r - a, 0)
		k2 = max(b - c - r, 0)
		print(k1 + k2)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	prev = c - r
	next = c + r
	time = 0
	s = max(prev, min(a, b))
	e = min(next, max(a, b))
	print(abs(b - a) - max(0, e - s))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = sorted([a, b])
	ans = 0
	f = 1
	if c - r <= a <= b <= c + r:
		f = 0
	if a <= c - r <= b:
		ans += c - r - a
		f = 0
	if a <= c + r <= b:
		ans += b - c - r
		f = 0
	if f == 1:
		ans += b - a
	print(ans)


t = int(input())
for i in range(t):
	time = 0
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if c > b:
		if a <= c - r <= b:
			time = c - r - a
		elif c - r > b:
			time = b - a
	elif c < a:
		if a <= c + r <= b:
			time = b - (c + r)
		elif c + r < a:
			time = b - a
	else:
		if c - r > a:
			time += c - r - a
		if c + r < b:
			time += b - (c + r)
	print(time)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(a, b, c, d) = MAP()
	(a, b) = (min(a, b), max(a, b))
	l = c - d
	r = c + d
	ans = 0
	ans += max(0, l - a)
	ans += max(0, b - r)
	ans = min(ans, b - a)
	print(ans)


from math import *
from collections import *
from itertools import *
from bisect import *
from heapq import *
from operator import *

def io():
	return map(int, input().split())

def op():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(a, b, c, r) = io()
	if a > b:
		(a, b) = (b, a)
	s = b - a
	(a1, b1) = (c - r, c + r)
	a1 = max(a1, a)
	b1 = min(b1, b)
	s1 = b1 - a1
	if s1 < 0:
		s1 = 0
	print(s - s1)


for _ in range(int(input())):
	(x, y, c, r) = map(int, input().split())
	x += 1000000000000000000000
	y += 1000000000000000000000
	c += 1000000000000000000000
	a = min(x, y)
	b = max(x, y)
	left = c - r
	right = c + r
	ans = 0
	if a < left:
		ans = left - a
	if b > right:
		ans += b - right
	if b < left:
		ans -= left - b
	if a > right:
		ans -= a - right
	print(ans)


T = int(input())
for t in range(T):
	(a, b, c, r) = [int(x) for x in input().split()]
	s = min(a, b)
	e = max(a, b)
	l = e - s
	if c >= s and c <= e:
		x = max(s, c - r)
		y = min(e, c + r)
		print(l - y + x)
	elif c < s:
		if r > s - c:
			if r < e - c:
				print(e - r - c)
			else:
				print(0)
		else:
			print(l)
	elif r > c - e:
		if r < c - s:
			print(c - r - s)
		else:
			print(0)
	else:
		print(l)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	ans = max(a, b) - min(a, b)
	if c > min(a, b) and c < max(a, b):
		if c - r <= min(a, b):
			ans = ans - (c - min(a, b))
		else:
			ans = ans - (c - (c - r))
		if c + r >= max(a, b):
			ans = ans - (max(a, b) - c)
		else:
			ans = ans - (c + r - c)
	elif c <= min(a, b):
		k = c + r
		if k >= max(a, b):
			ans = 0
		elif k > min(a, b) and k < max(a, b):
			ans = ans - (k - min(a, b))
	elif c >= max(a, b):
		k = c - r
		if k <= min(a, b):
			ans = 0
		elif k < max(a, b) and k > min(a, b):
			ans = ans - (max(a, b) - k)
	print(ans)


import sys
from collections import defaultdict as dd
from itertools import permutations as pp
from itertools import combinations as cc
from collections import Counter as ccd
from random import randint as rd
from bisect import bisect_left as bl
from heapq import heappush as hpush
from heapq import heappop as hpop
mod = 10 ** 9 + 7

def ri(flag=0):
	if flag == 0:
		return [int(i) for i in sys.stdin.readline().split()]
	else:
		return int(sys.stdin.readline())
for _ in range(ri(1)):
	(a, b, c, r) = ri()
	tot = abs(a - b)
	le = c - r
	right = c + r
	if a > b:
		(a, b) = (b, a)
	le = max(a, le)
	right = min(right, b)
	if le < right:
		tot = tot - abs(le - right)
	print(tot)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if c + r < a or c - r > b:
		print(b - a)
	elif a in range(c - r, c + r + 1) and b not in range(c - r, c + r + 1):
		print(abs(b - (c + r)))
	elif b in range(c - r, c + r + 1) and a not in range(c - r, c + r + 1):
		print(abs(a - (c - r)))
	elif a in range(c - r, c + r + 1) and b in range(c - r, c + r + 1):
		print(0)
	else:
		print(abs(b - a - 2 * r))


N = int(input())
for i in range(N):
	(a, b, c, r) = map(int, input().split())
	l = min(a, b)
	h = max(a, b)
	ans = h - l
	lb = max(l, c - r)
	rb = min(h, c + r)
	cs = max(0, rb - lb)
	ans = ans - cs
	print(ans)


for _ in range(int(input())):
	(x, y, c, d) = map(int, input().split())
	mi = c - d
	ma = c + d
	a = min(x, y)
	b = max(x, y)
	if ma <= a:
		print(abs(b - a))
	elif mi >= b:
		print(abs(b - a))
	elif mi >= a and ma <= b:
		print(abs(b - a - 2 * d))
	elif 2 * d > b - a and ma >= b and (mi <= a):
		print(0)
	elif mi < a and ma > a:
		print(abs(b - ma))
	elif ma > b and mi < b:
		print(abs(mi - a))


t = int(input())
for z in range(t):
	sum = 0
	(a, b, c, r) = map(int, input().split())
	if a > b:
		temp = a
		a = b
		b = temp
	if min(c + r, a) == c + r:
		print(b - a)
		continue
	if min(c - r, b) == b:
		print(b - a)
		continue
	if min(c - r, a) == a:
		sum = c - r - a
	if max(c + r, b) == b:
		sum += b - (c + r)
	print(sum)


i = int(input())
for k in range(i):
	(s, e, station, radius) = map(int, input().split(' '))
	covered_steps = 0
	start = min(s, e)
	end = max(s, e)
	if station + radius <= end and station - radius >= start:
		covered_steps = station + radius - (station - radius)
		print(end - start - covered_steps)
	elif station + radius <= start or station - radius >= end:
		print(end - start - covered_steps)
	elif station + radius >= end and station - radius >= start:
		covered_steps = end - (station - radius)
		print(end - start - covered_steps)
	elif station + radius <= end and station - radius <= start:
		covered_steps = station + radius - start
		print(end - start - covered_steps)
	elif station + radius >= end and station - radius <= start:
		print(covered_steps)


def solution(a, b, c, r):
	ma = max(a, b)
	mi = min(a, b)
	j = 0
	if c - r >= ma or c + r <= mi:
		j = ma - mi
	elif c - r <= mi and c + r <= ma:
		j = ma - c - r
	elif c - r >= mi and c + r <= ma:
		j = ma - mi - 2 * r
	elif c - r >= mi:
		j = c - r - mi
	print(j)
n = int(input())
for i in range(n):
	solution(*list(map(int, input().split())))


def main():
	cases = int(input())
	for case in range(cases):
		(t1, t2, c, r) = map(int, input().strip().split())
		a = min(t1, t2)
		b = max(t1, t2)
		if c + r >= b and c - r <= a:
			print(0)
		elif c + r <= b and c - r >= a:
			print(abs(c - r - a) + abs(b - c - r))
		elif c + r >= a and c + r <= b:
			print(abs(b - (c + r)))
		elif c - r <= b and c - r >= a:
			print(abs(c - r - a))
		else:
			print(abs(b - a))
main()


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split(' ')]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n').split(' ')]

def li3():
	return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
	(a, b, c, r) = li()
	if a > b:
		(a, b) = (b, a)
	if c < a:
		tot = max(0, b - a - max(0, c + r - a))
	elif c < b:
		tot = max(0, max(0, c - r - a) + max(0, b - (c + r)))
	else:
		tot = max(0, b - a - max(0, b - (c - r)))
	print(tot)


for j in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		d = b
		b = a
		a = d
	ans = 0
	if c + r <= a or c - r >= b:
		print(b - a)
		continue
	elif c + r >= a and c - r <= a and (c + r <= b):
		ans = b - c - r
	elif c - r >= a and c + r <= b:
		ans = b - a - 2 * r
	else:
		ans = c - r - a
	if ans < 0:
		print(0)
	else:
		print(min(ans, b - a))


N = int(input())
grid = list()
for i in range(N):
	row = list(map(int, input().split()))
	grid.append(row)

def func(hairetsu):
	a = min(hairetsu[0], hairetsu[1])
	b = max(hairetsu[0], hairetsu[1])
	c = hairetsu[2]
	r = hairetsu[3]
	if a <= c - r and c + r <= b:
		S = b - a - 2 * r
		print(S)
	elif c - r < a and b < c + r:
		print(0)
	elif b < c + r:
		if c - r <= b:
			S = c - r - a
			print(S)
		elif b < c - r:
			S = b - a
			print(S)
	elif c - r < a:
		if a <= c + r:
			S = b - c - r
			print(S)
		elif c + r < a:
			S = b - a
			print(S)
for i in range(N):
	func(grid[i])


a = int(input())
for i in range(a):
	abcr = list(map(int, input().split()))
	a = abcr[0]
	b = abcr[1]
	c = abcr[2]
	r = abcr[3]
	if a > b:
		(a, b) = (b, a)
	T = b - a + 1
	R0 = c - r
	R1 = c + r
	if R0 >= a and R1 <= b:
		print(b - a - 2 * r)
	elif R0 > b or R1 < a:
		print(b - a)
	elif R0 <= a and R1 <= b:
		print(T - (R1 - a + 1))
	elif R0 >= a and R1 >= b:
		print(T - (b - R0 + 1))
	elif R0 <= a and R1 >= b:
		print(0)


t = int(input())
l = []
for i in range(t):
	(a, b, c, r) = map(int, input().strip().split())
	if a <= c <= b or b <= c <= a:
		if a > b:
			(a, b) = (b, a)
		x1 = c - r
		x2 = c + r
		if x2 >= b:
			if x1 <= a:
				l.append(0)
			else:
				l.append(x1 - a)
		elif x1 <= a:
			l.append(b - x2)
		else:
			l.append(b - x2 + x1 - a)
	if c > max(a, b):
		if a > b:
			(a, b) = (b, a)
		x1 = c - r
		if x1 < a:
			l.append(0)
		elif x1 > b:
			l.append(b - a)
		else:
			l.append(x1 - a)
	if c < min(a, b):
		if a > b:
			(a, b) = (b, a)
		x2 = c + r
		if x2 > b:
			l.append(0)
		elif x2 < a:
			l.append(b - a)
		else:
			l.append(b - x2)
for i in range(t):
	print(l[i])


t = int(input())
for _ in range(t):
	(a, b, c, r) = list(map(int, input().strip().split()))
	(a, b) = (min(a, b), max(a, b))
	low = max(a, c - r)
	high = min(b, c + r)
	unavaialbe = high - low
	unavaialbe = max(unavaialbe, 0)
	print(b - a - unavaialbe)


import sys
reader = (map(int, s.split()) for s in sys.stdin)

def func(a, b, c, r):
	if a > b:
		(a, b) = (b, a)
	add1 = min(b - a, max(c - r - a, 0))
	add2 = min(b - a, max(b - (c + r), 0))
	return add1 + add2
(t,) = next(reader)
for _ in range(t):
	(a, b, c, r) = next(reader)
	ans = func(a, b, c, r)
	print(ans)


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = 1
t = inp()
for tt in range(t):
	(a, b, c, r) = map(int, input().split())
	(q, w) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	print(b - a - max(0, min(b, c + r) - max(a, c - r)))


(T, j, y) = (int(input()), 0, [])
while j < T:
	z = list(map(int, input().split()))
	y.append(z)
	(a, b, c, r) = (z[0], z[1], z[2], z[3])
	if a > b:
		(a, b) = (b, a)
	if c <= a and c <= b and (r >= b - c):
		y[j].append(0)
	elif c >= a and c >= b and (r >= c - a):
		y[j].append(0)
	elif c <= a and c <= b and (r > a - c):
		y[j].append(b - a - (r - a + c))
	elif c <= a and c <= b and (r <= a - c):
		y[j].append(b - a)
	elif c >= a and c >= b and (r > c - b):
		y[j].append(b - a - (r - c + b))
	elif c >= a and c >= b and (r <= c - b):
		y[j].append(b - a)
	elif c >= a and c <= b and (c - a <= r) and (b - c <= r):
		y[j].append(0)
	elif c >= a and c <= b and (c - a >= r) and (b - c <= r):
		y[j].append(c - a - r)
	elif c >= a and c <= b and (c - a <= r) and (b - c >= r):
		y[j].append(b - c - r)
	elif c >= a and c <= b and (c - a >= r) and (b - c >= r):
		y[j].append(b - a - 2 * r)
	j += 1
j = 0
while j < T:
	print(y[j][4])
	j += 1


import sys
import math
import itertools
import functools
import collections

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
t = ii()
for _ in range(t):
	(a, b, c, r) = mi()
	if a > b:
		(a, b) = (b, a)
	if b <= c - r or a >= c + r:
		print(b - a)
	elif a <= c - r and c + r <= b:
		print(b - a - r * 2)
	elif c - r <= a and b <= c + r:
		print(0)
	elif a <= c - r and b <= c + r:
		print(c - r - a)
	elif c - r <= a and c + r <= b:
		print(b - c - r)


from sys import stdin
input = stdin.readline
for xoxo in range(1):
	for _ in range(int(input())):
		p = 10 ** 8 + 5
		(a, b, c, r) = map(int, input().split())
		a += p
		b += p
		c += p
		(a, b) = (min(a, b), max(a, b))
		if c < a:
			ans = max(min(b - c - r, b - a), 0)
		elif c > b:
			if c - r >= b:
				ans = b - a
			elif c - r > a:
				ans = c - r - a
			else:
				ans = 0
		else:
			x = max(c - r, a)
			y = min(c + r, b)
			ans = b - a - (y - x)
		print(ans)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(t, v) = (c - r, c + r)
	(a, b) = (min(a, b), max(a, b))
	ab = abs(b - a)
	if a >= t and a >= v or (b <= t and b <= v):
		print(ab)
	elif a <= t and b >= v:
		print(ab - 2 * r)
	elif a >= t and b <= v:
		print(0)
	elif a >= t and v <= b:
		print(ab - abs(v - a))
	elif a <= t and b <= v:
		print(ab - abs(b - t))


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	low = c - r
	high = c + r
	(a, b) = (b, a) if b < a else (a, b)
	if a == b:
		print(0)
		continue
	intersection = 0
	if low <= a:
		if high <= a:
			intersection = 0
		elif high >= b:
			intersection = b - a
		else:
			intersection = high - a
	elif low >= b:
		intersection = 0
	elif high >= b:
		intersection = b - low
	else:
		intersection = high - low
	print(b - a - intersection)


for i in range(int(input())):
	p = 0
	q = 0
	(a, b, c, r) = map(int, input().split())
	if a > b:
		d = b
		b = a
		a = d
	b = max(b, a)
	s = c - r
	l = c + r
	if (s >= a and s <= b) and (l >= a and l <= b):
		p = s - a
		q = b - l
	elif (s <= a and s <= b) and (l < a and l < b):
		p = b - a
		q = 0
	elif (s >= a and s <= b) and (l >= a and l >= b):
		p = s - a
		q = 0
	elif (s <= a and s <= b) and (l >= a and l <= b):
		p = b - l
		q = 0
	elif (l >= a and l >= b) and (s >= a and s >= b):
		p = b - a
		q = 0
	print(p + q)


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		temp = a
		a = b
		b = temp
	if a >= c + r:
		print(b - a)
	elif b <= c - r:
		print(b - a)
	elif a >= c - r and b <= c + r:
		print(0)
	elif a >= c - r and b >= c + r:
		print(b - c - r)
	elif a <= c - r and b <= c + r:
		print(c - r - a)
	elif b >= c + r and a <= c - r:
		print(c - r - a + b - c - r)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if b >= a:
		if a <= c - r:
			if b <= c - r:
				print(b - a)
			elif b >= c - r and b <= c + r:
				print(c - r - a)
			else:
				print(b - a - 2 * r)
		elif a >= c - r and a <= c + r:
			if b >= c - r and b <= c + r:
				print(0)
			else:
				print(b - c - r)
		else:
			print(b - a)
	elif b <= c - r:
		if a <= c - r:
			print(-b + a)
		elif a >= c - r and a <= c + r:
			print(c - r - b)
		else:
			print(-b + a - 2 * r)
	elif b >= c - r and b <= c + r:
		if a >= c - r and a <= c + r:
			print(0)
		else:
			print(a - c - r)
	else:
		print(a - b)


from sys import stdin, stdout
from math import *
for __ in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(x, y) = (c - d, c + d)
	ans = 0
	if a >= x and b <= y:
		ans = 0
	elif a <= x and b >= y:
		ans = x - a + b - y
	elif x <= a and y >= b:
		ans = b - a
	elif b <= x or a >= y:
		ans = b - a
	elif a <= x and x <= b <= y:
		ans = x - a
	elif a >= x and a <= y <= b:
		ans = b - y
	print(ans)


for _ in range(int(input())):
	(from_, to, station, radius) = map(int, input().split())
	if to < from_:
		(from_, to) = (to, from_)
	signalLeft = station - radius
	signalRight = station + radius
	ret = to - from_
	if signalLeft > to or signalRight < from_:
		print(ret)
	else:
		hasLeft = max(signalLeft, from_)
		hasRight = min(signalRight, to)
		print(ret - (hasRight - hasLeft))


t = int(input())
for _ in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	l = [a, b]
	l.sort()
	(a, b) = l
	if a <= c <= b or b <= c <= a:
		x = max(c - r - a, 0)
		y = max(b - c - r, 0)
		print(x + y)
	else:
		l = [a, b]
		l.sort()
		(a, b) = (l[0], l[1])
		if b + r <= c or c <= a - r:
			print(abs(a - b))
		elif abs(b - c) < abs(a - c):
			print(max(abs(a - b) - (r - c + b), 0))
		else:
			print(max(abs(a - b) - (r - a + c), 0))


import sys
queries = int(sys.stdin.readline())

def doQueries(queries):
	for query in range(queries):
		(start, end, station, radius) = map(int, sys.stdin.readline().split())
		if end < start:
			(start, end) = (end, start)
		startNetwork = station - radius
		endNetwork = station + radius
		if endNetwork < startNetwork:
			(endNetwork, startNetwork) = (startNetwork, endNetwork)
		if endNetwork < start or startNetwork > end:
			print(end - start)
		else:
			if startNetwork < start:
				startNetwork = start
			if endNetwork > end:
				endNetwork = end
			print(end - start - (endNetwork - startNetwork))
doQueries(queries)


def solve():
	ints = list(map(int, input().split(' ')))
	a = min(ints[0], ints[1])
	b = max(ints[0], ints[1])
	d = ints[2] - ints[3]
	e = ints[2] + ints[3]
	tmp = min(e, b) - max(a, d)
	tmp = tmp if tmp > 0 else 0
	if b < d or a > e:
		print(b - a)
	else:
		print(b - a - tmp)
T = int(input())
for _ in range(T):
	solve()


n = int(input())
for i in range(n):
	a = [int(i) for i in input().split(' ')]
	rast = abs(a[0] - a[1])
	if a[0] > a[1]:
		(a[0], a[1]) = (a[1], a[0])
	x1 = a[2] - a[3]
	x2 = a[2] + a[3]
	if x2 > a[1]:
		x2 = a[1]
	if x1 < a[0]:
		x1 = a[0]
	if x2 <= a[0] or x1 >= a[1]:
		time = a[1] - a[0]
	else:
		time = x1 - a[0] + a[1] - x2
	print(time)


for _ in [0] * int(input()):
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	left_c = max(min(a, b), left)
	right_c = min(max(a, b), right)
	print(abs(b - a) - max(0, right_c - left_c))


def f(l):
	(a, b, c, r) = l
	if a > b:
		(a, b) = (b, a)
	c1 = c - r
	c2 = c + r
	if b <= c1 or a >= c2:
		return b - a
	return max(c1 - a, 0) + max(0, b - c2)
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print(f(l))


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(q, p) = (c - r, c + r)
	if b < q or p < a:
		print(b - a)
	elif a <= q and p <= b:
		print(b - a - r - r)
	elif q < a and b < p:
		print(0)
	elif b < p:
		print(q - a)
	elif q < a:
		print(b - p)


def circle(t, r):
	return t * t - r * r
for _ in range(int(input())):
	(p, q, c, r) = map(int, input().strip().split())
	b = max(p, q) - c
	a = min(p, q) - c
	l1 = circle(a, r)
	l2 = circle(b, r)
	tot = b - a
	c = 0
	if l1 <= 0 and l2 <= 0:
		print(0)
	elif l1 > 0 and l2 > 0:
		if c >= a and c <= b:
			print(tot - 2 * r)
		else:
			print(tot)
	elif l1 > 0 and l2 <= 0:
		print(tot - (b + r))
	else:
		print(tot - (r - a))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split(' '))
	coverage_start = c - r
	coverage_end = c + r
	real_start = min(a, b)
	real_end = max(a, b)
	time = abs(b - a)
	answer = time - max(0, min(coverage_end, real_end) - max(coverage_start, real_start))
	print(answer)


def test(a, b, c, r):
	left = c - r
	right = c + r
	if a > b:
		(a, b) = (b, a)
	if r == 0:
		print(b - a)
	elif left >= a and right <= b:
		print(b - a - right + left)
	elif left < a and right > b:
		print(0)
	elif left < a and right < a or (left > b and right > b):
		print(b - a)
	elif left < a:
		print(b - right)
	elif right > b:
		print(left - a)
for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	test(a, b, c, r)


def main():
	t = int(input())
	for i in range(t):
		(a, b, c, r) = map(int, input().split())
		c1 = c - r
		c2 = c + r
		if b < a:
			temp1 = a
			a = b
			b = temp1
		if c2 <= a or c1 >= b:
			print(abs(b - a))
			continue
		if c2 >= b and c1 <= a:
			print(0)
			continue
		if c2 <= b and c1 >= a:
			print(abs(a - b) - abs(c2 - c1))
			continue
		if c1 <= a and c2 <= b:
			print(abs(c2 - b))
			continue
		if c1 >= a and c2 >= b:
			print(abs(c1 - a))
			continue
main()


def network(a, b, c1, c2):
	if c1 >= b or c2 <= a:
		return b - a
	left = 0 if c1 <= a else c1 - a
	right = 0 if c2 >= b else b - c2
	return left + right
for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	c1 = c - r
	c2 = c + r
	if a > b:
		(a, b) = (b, a)
	print(network(a, b, c1, c2))


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	(x, y) = (c - r, c + r)
	d = max(0, min(b, y) - max(x, a))
	print(b - a - d)


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	(cl, ch) = (min(c - r, c + r), max(c - r, c + r))
	cnt = 0
	if a < cl:
		cnt += min(cl, b) - a
	if b > ch:
		cnt += b - max(ch, a)
	print(cnt)


def solve(a, b, c, r):
	(a, b) = sorted([a, b])
	(c1, c2) = (c - r, c + r)
	res = 0
	if (c1 >= a and c1 <= b) and (c2 >= a and c2 <= b):
		res = abs(c1 - a) + abs(b - c2)
	elif c1 < a and (c2 >= a and c2 <= b):
		res = abs(b - c2)
	elif (c1 >= a and c1 <= b) and c2 > b:
		res = abs(c1 - a)
	elif c1 < a and c2 > b:
		res = 0
	elif c1 > b and c2 > b or (c1 < a and c2 < a):
		res = abs(b - a)
	print(res)
t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	solve(a, b, c, r)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().strip().split())
	min_range = c - r
	max_range = c + r
	(a, b) = (min(a, b), max(a, b))
	if b < min_range or a > max_range:
		print(b - a)
		continue
	un1 = min_range - a
	un1 = max(0, un1)
	un2 = b - max_range
	un2 = max(0, un2)
	print(un1 + un2)


import sys
n = int(sys.stdin.readline())
for i in range(0, n):
	line = sys.stdin.readline().split()
	sebr = list(map(int, line))
	start = sebr[0]
	end = sebr[1]
	b = sebr[2]
	r = sebr[3]
	if start > end:
		(start, end) = (end, start)
	radius_start = b - r
	radius_end = b + r
	total = abs(end - start)
	if radius_end < start or radius_start > end:
		print(total)
		continue
	if radius_end <= end and radius_start >= start:
		total -= radius_end - radius_start
		print(total)
		continue
	if radius_end >= end and radius_start <= start:
		total = 0
		print(total)
		continue
	if radius_end >= start and radius_start <= start:
		start = radius_end
		total = abs(end - start)
		print(total)
		continue
	if radius_start <= end and radius_end >= end:
		end = radius_start
		total = abs(end - start)
		print(total)
		continue


t = int(input())
while t > 0:
	(a, b, c, r) = input().split(' ')
	a = int(a)
	b = int(b)
	c = int(c)
	r = int(r)
	ans = 0
	if a < b:
		startpos = a
		endpos = b
	else:
		startpos = b
		endpos = a
	if r == 0:
		ans = endpos - startpos
	elif startpos != endpos:
		if c <= startpos:
			temp1 = c + r
			if temp1 >= endpos:
				ans = 0
			else:
				ans = endpos - max(startpos, temp1)
		elif c >= endpos:
			temp2 = c - r
			if temp2 <= startpos:
				ans = 0
			else:
				ans = min(endpos, temp2) - startpos
		elif c > startpos and c < endpos:
			temp1pos = c - r
			temp2pos = c + r
			if temp1pos <= startpos and temp2pos >= endpos:
				ans = 0
			elif temp2pos >= endpos and temp1pos > startpos:
				ans = temp1pos - startpos
			elif temp2pos < endpos and temp1pos <= startpos:
				ans = endpos - temp2pos
			elif temp2pos < endpos and temp1pos > startpos:
				ans = endpos - temp2pos + (temp1pos - startpos)
	print(ans)
	t = t - 1


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		t = a
		a = b
		b = t
	ans = b - a
	p1 = min(c - r, c + r)
	p2 = max(c - r, c + r)
	if p1 > b or p2 < a:
		pass
	elif p2 >= b and p1 <= a:
		ans = 0
	elif p1 < a:
		ans = ans - (p2 - a)
	elif p2 > b:
		ans = ans - (b - p1)
	else:
		ans = ans - (p2 - p1)
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		temp = a
		a = b
		b = temp
	d = c - r
	e = c + r
	if a > e or d > b:
		print(b - a)
	elif e >= b and d >= a:
		print(d - a)
	elif e >= b and d < a:
		print(0)
	elif e < b and d < a:
		print(b - e)
	else:
		print(b - a - 2 * r)


for _ in range(int(input())):
	(a, b, c, r) = tuple(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	lb = c - r
	ub = c + r
	if b <= lb or ub <= a:
		res = b - a
	elif a <= lb <= ub <= b:
		res = b - a - (ub - lb)
	elif a <= lb <= b <= ub:
		res = lb - a
	elif lb <= a <= ub <= b:
		res = b - ub
	elif lb <= a <= b <= ub:
		res = 0
	print(res)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	left = c - r
	right = c + r
	ans = 0
	if min(a, b) < left:
		ans += left - min(a, b)
	if max(a, b) > right:
		ans += max(a, b) - right
	print(min(ans, abs(b - a)))


n = int(input())
p = []
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	x = c - r
	y = c + r
	if a > b:
		(a, b) = (b, a)
	if a <= x and b <= x:
		p.append(b - a)
	elif y <= a and y <= b:
		p.append(b - a)
	elif x <= a and b <= y:
		p.append('0')
	elif a <= x and y <= b:
		p.append(x - a + (b - y))
	elif a <= x and x <= b <= y:
		p.append(x - a)
	elif x <= a and a <= y <= b:
		p.append(b - y)
for i in p:
	print(i)


from math import *
t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	x = min(a, b)
	y = max(a, b)
	p = c - r
	q = c + r
	if y < p or q < x:
		print(y - x)
	else:
		o = min(y, q) - max(x, p)
		print(y - x - o)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	temp1 = c - r
	temp2 = c + r
	time = 0
	if a > b:
		(a, b) = (b, a)
	fl1 = 0
	fl2 = 0
	if temp1 > a and temp1 < b:
		fl1 = 1
	if temp2 > a and temp2 < b:
		fl2 = 1
	if fl1 == 1 and fl2 == 1:
		time += 2 * r
	elif fl1 == 1 and fl2 == 0:
		time += b - temp1
	elif fl1 == 0 and fl2 == 1:
		time += temp2 - a
	if temp1 <= a and temp2 >= b:
		time += b - a
	print(b - a - time)


for io in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	count = 0
	(a, b) = (min(a, b), max(a, b))
	if c - r < a:
		start = a
	else:
		start = c - r
	if c + r < a:
		end = a
	elif c + r >= a and c + r <= b:
		end = c + r
	else:
		end = b
	value = b - a - max(0, end - start)
	print(value)


n = int(input())
for i in range(n):
	ans = int(0)
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ll = c - r
	rr = c + r
	ll = max(a, ll)
	rr = min(b, rr)
	d = max(rr - ll, 0)
	ans = b - a - d
	print(ans)


import math
q = [[int(e) for e in r.split()] for r in [input() for i in range(int(input()))]]
for i in q:
	s = 1
	if i[0] > i[1]:
		temp = i[1]
		i[1] = i[0]
		i[0] = temp
	temp = i[3]
	i[3] = i[2] - temp
	i[2] = i[2] + temp
	for t in range(2):
		if i[2 + t] < i[0]:
			i[2 + t] = i[0]
		elif i[2 + t] > i[1]:
			i[2 + t] = i[1]
	print(abs(i[1] - i[0] - i[2] + i[3]))


n = int(input().strip())

def test_1(n):
	for i in range(n):
		(a, b, c, r) = list(map(int, input().split(' ')))
		if a > b:
			(b, a) = (a, b)
		x = c - r
		y = c + r
		if a <= x <= y <= b:
			d = b - a - 2 * r
		if a <= x <= b <= y:
			d = x - a
		if a <= b <= x <= y:
			d = b - a
		if x <= a <= y <= b:
			d = b - y
		if x <= a <= b <= y:
			d = 0
		if x <= y <= a <= b:
			d = b - a
		print(d)
test_1(n)


def count_min(c1, c2, c, d):
	count = 0
	if c2 > c + d or c1 < c - d:
		count = 0
		return count
	if c1 <= c + d and c2 >= c - d:
		count = min
	elif c1 <= c + d and c2 < c - d:
		count = c1 - (c - d)
	elif c2 >= c - d and c1 > c + d:
		count = c + d - c2
	elif c2 < c - d and c1 > c + d:
		count = 2 * d
	return count
t = int(input())
while t > 0:
	(a, b, c, d) = map(int, input().split())
	if a > b:
		c1 = a
		c2 = b
	else:
		c1 = b
		c2 = a
	count = 0
	min = c1 - c2
	res = min - count_min(c1, c2, c, d)
	if res < 0:
		res = 0
	print(res)
	t -= 1


a = int(input())
for i in range(0, a):
	k = [int(x) for x in input().split()]
	start = max(k[2] - k[3], min(k[0], k[1]))
	end = min(k[2] + k[3], max(k[0], k[1]))
	print(abs(k[0] - k[1]) - max(0, end - start))


t = int(input())
for o in range(t):
	(a, b, c, r) = map(int, input().strip().split())
	mx = max(a, b)
	mn = min(a, b)
	ans = 0
	if mn <= c - r:
		ans += c - r - mn
	elif mn >= c + r:
		ans -= mn - c - r
	if mx <= c - r:
		ans -= c - r - mx
	elif mx >= c + r:
		ans += mx - c - r
	print(ans)


for _ in range(int(input())):
	(a, b, c2, r2) = map(int, input().split())
	c1 = (a + b) / 2
	r1 = abs(c1 - a)
	d = abs(c1 - c2)
	if d < r1 + r2 and d > abs(r1 - r2):
		print(int(2 * r1 - (r1 + r2 - d)))
	elif d >= r1 + r2:
		print(int(2 * r1))
	elif r1 > r2:
		print(int(2 * abs(r1 - r2)))
	else:
		print('0')


for tin in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	x = c - r - a
	y = b - (c + r)
	if c + r < min(a, b):
		print(abs(a - b))
	elif c - r > max(a, b):
		print(abs(a - b))
	else:
		if x <= 0:
			x = 0
		if y <= 0:
			y = 0
		print(x + y)


try:
	t = int(input())
	for i in range(t):
		(a, b, c, r) = map(int, input().split())
		L = max(min(a, b), c - r)
		R = min(max(a, b), c + r)
		print(max(a, b) - min(a, b) - max(0, R - L))
except EOFError:
	pass


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(2 * n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(a, b, c, r) = value()
	(a, b) = (min(a, b), max(a, b))
	res1 = c - r - min(c - r, a)
	res2 = b - min(b, c + r)
	print(min(b - a, res1 + res2))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split(' '))
	if a > b:
		t = b
		b = a
		a = t
	cova = c - r
	covb = c + r
	s = sorted([a, b, cova, covb])
	tot = 0
	if s[0] == a:
		tot += s[1] - s[0]
		if s[1] == b:
			print(tot)
			continue
		elif s[2] == b:
			print(tot)
			continue
		else:
			tot += b - s[2]
			print(tot)
			continue
	elif s[1] == a:
		if s[2] == b:
			print(0)
			continue
		else:
			print(b - covb)
			continue
	elif s[2] == a:
		print(b - a)
		continue


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	x = c - r
	y = c + r
	aa = 0
	if x > b or y < a:
		print(b - a)
		continue
	x = max(x, a)
	y = min(y, b)
	ans = x - a + (b - y)
	print(ans)


import sys
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	(a, b, c, r) = map(int, I().split())
	left_area = c - r
	right_area = c + r
	(a, b) = (min(a, b), max(a, b))
	time = 0
	distance = b - a
	if a == b:
		time = 0
	elif a >= left_area and b <= right_area:
		time = 0
	elif b <= left_area:
		time = distance
	elif a >= right_area:
		time = distance
	elif a < left_area and b > right_area:
		time = left_area - a + (b - right_area)
	elif a < left_area and b > left_area:
		time = left_area - a
	else:
		time = b - right_area
	ans += str(time) + '\n'
print(ans)


T = int(input())
for _ in range(T):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	l = max(a, c - r)
	r = min(b, c + r)
	print(b - a) if r <= l else print(b - a - (r - l))


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	x = 0
	s = max(a, b)
	y = min(a, b)
	if c >= y and c <= s:
		if c - y >= r:
			x = x + r
		else:
			x = x + c - y
		if s - c >= r:
			x = x + r
		else:
			x = x + s - c
		print(s - y - x)
	else:
		if c < y:
			if y - c <= r and s - c <= r:
				x = s - y
			elif y - c <= r:
				x = x + r - y + c
			print(s - y - x)
		if c > s:
			if c - s <= r and c - y <= r:
				x = s - y
			elif c - s <= r:
				x = x + r + s - c
			print(s - y - x)


for _ in range(int(input())):
	(aa, ba, c, r) = map(int, input().split())
	b = max(aa, ba)
	a = min(aa, ba)
	if c <= a:
		if c + r <= a:
			print(max(0, b - a))
		else:
			print(max(0, b - (c + r)))
	elif c >= b:
		if c - r >= b:
			print(max(0, b - a))
		else:
			print(max(0, c - r - a))
	else:
		r = min(c + r, b) - max(a, c - r)
		print(max(0, b - a - r))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(a, b, c, r) = LI()
		if a > b:
			(a, b) = (b, a)
		if c - r <= a:
			a = max(a, c + r)
		elif c + r >= b:
			b = min(b, c - r)
		else:
			a += r * 2
		rr.append(max(b - a, 0))
	return JA(rr, '\n')
print(main())


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	ans = 0
	if a > b:
		(a, b) = (b, a)
	l = c - r
	r = c + r
	ll = max(a, l)
	rr = min(b, r)
	ans = b - a
	if ll <= rr:
		ans -= rr - ll
	print(ans)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b, c, r) = map(int, sys.stdin.readline().split())
	(a, b) = (min(a, b), max(a, b))
	coverage_a = c - r
	coverage_b = c + r
	left = max(a, coverage_a)
	right = min(b, coverage_b)
	ans = b - a - max(right - left, 0)
	print(ans)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	ld = c - r
	rd = c + r
	ans = 0
	temp = max(a, b)
	a = min(a, b)
	b = temp
	if (ld - a) * (rd - a) < 0 and (ld - b) * (rd - b) < 0:
		ans = 0
	elif b < ld or a > rd:
		ans = b - a
	elif a < ld and b > rd:
		ans = ld - a + b - rd
	elif a < ld:
		ans = ld - a
	elif b > rd:
		ans = b - rd
	print(ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def main():
	for _ in range(ri()):
		(a, b, c, r) = ria()
		s1 = (c - r, c + r)
		s2 = (min(a, b), max(a, b))
		ans = abs(b - a) - max(0, min(s1[1], s2[1]) - max(s1[0], s2[0]))
		wi(ans)
main()


test = int(input())
for t in range(test):
	(a, b, c, r) = [int(x) for x in input().split(' ')]
	(cs, ce, wait) = (c - r, c + r, 0)
	if a > b:
		(a, b) = (b, a)
	if (a >= cs and a <= ce) and (b >= cs and b <= ce):
		print(0)
		continue
	elif not (cs >= a and cs <= b) and (not (ce >= a and ce <= b)):
		print(b - a)
		continue
	else:
		if cs >= a and cs <= b:
			wait += cs - a
		if ce >= a and ce <= b:
			wait += b - ce
		print(wait)


t = input()
for i in range(0, int(t)):
	inp = input()
	num = inp.split()
	if int(num[0]) > int(num[1]):
		a = int(num[1])
		b = int(num[0])
	else:
		a = int(num[0])
		b = int(num[1])
	c = int(num[2])
	r = int(num[3])
	mini = c - r
	maxi = c + r
	if (maxi < a or mini > b) or ((b == c or a == c) and r == 0):
		cover = len(range(a, b))
		print(cover)
	elif mini <= a and maxi >= b or a == b:
		print(0)
	elif maxi <= b and mini >= a:
		cover = len(range(a, b)) - (maxi - mini)
		print(cover)
	elif maxi < b and mini <= a:
		cover = len(range(a, b)) - (maxi - a)
		print(cover)
	elif maxi >= b and mini > a:
		cover = len(range(a, b)) - (b - mini)
		print(cover)


n = int(input())
for i in range(n):
	caso = list(map(int, input().split(' ')))
	if caso[0] > caso[1]:
		aux = caso[1]
		caso[1] = caso[0]
		caso[0] = aux
	if caso[0] <= caso[2] - caso[3] and caso[1] >= caso[2] + caso[3]:
		print(caso[1] - caso[3] * 2 - caso[0])
	elif caso[1] < caso[2] - caso[3] or caso[0] > caso[2] + caso[3]:
		print(caso[1] - caso[0])
	elif caso[1] >= caso[2] + caso[3]:
		print(caso[1] - caso[2] - caso[3])
	elif caso[0] <= caso[2] - caso[3]:
		print(caso[2] - caso[3] - caso[0])
	else:
		print(0)


import math
for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	aa = min(a, b)
	bb = max(a, b)
	ri = c + r
	le = c - r
	ll = max(le, aa)
	rr = min(ri, bb)
	if rr < ll:
		print(bb - aa)
	else:
		t1 = rr - ll
		if t1 > bb - aa:
			print(0)
		else:
			print(bb - aa - t1)


from sys import stdin
input = stdin.readline
n = int(input())
for i in range(n):
	(a1, b1, c, r) = map(int, input().split(' '))
	a = min(a1, b1)
	b = max(a1, b1)
	d = b - a
	e = min(c + r, b) - max(c - r, a)
	if e < 0:
		e = 0
	print(d - e)


t = int(input())
for _ in range(t):
	(a, b, c, r) = map(int, input().split())
	maxi = max(a, b)
	mini = min(a, b)
	if c < mini:
		if c + r >= maxi:
			print(0)
		elif c + r <= mini:
			print(maxi - mini)
		else:
			print(maxi - (c + r))
	elif c > maxi:
		if c - r <= mini:
			print(0)
		elif c - r >= maxi:
			print(maxi - mini)
		else:
			print(c - r - mini)
	elif c - r <= mini and c + r >= maxi:
		print(0)
	elif c + r >= maxi:
		print(c - r - mini)
	elif c - r <= mini:
		print(maxi - (c + r))
	else:
		print(maxi - (c + r) + c - r - mini)


import math

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def solve():
	(a, b, c, r) = Read.list_int()
	m = min(a, b, c)
	if m < 0:
		a += -m
		b += -m
		c += -m
	if a > b:
		tmp = a
		a = b
		b = tmp
	if a >= c + r or b <= c - r:
		print(b - a)
		return
	t = max(c - r - a, 0)
	t2 = max(b - (c + r), 0)
	print(t2 + t)
query_count = Read.int()
while query_count:
	query_count -= 1
	solve()


n = int(input())
for i in range(n):
	(a, b, c, r) = (int(x) for x in input().split())
	s = max(min(a, b), c - r)
	f = min(max(a, b), c + r)
	print(max(a, b) - min(a, b) - max(0, f - s))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(c1, c2) = (c - r, c + r)
	if c1 < a and c2 < a:
		print(b - a)
	elif c1 > b and c2 > b:
		print(b - a)
	else:
		print(b - a - (min(b, c2) - max(a, c1)))


for t in range(int(input())):
	lst = list(map(int, input().split()))
	(lst[0], lst[1]) = (min(lst[0], lst[1]), max(lst[0], lst[1]))
	ans = min(lst[1] - lst[0], max(0, lst[2] - lst[3] - lst[0]) + max(0, lst[1] - lst[2] - lst[3]))
	print(ans)


for _ in range(int(input())):
	(l1, l2, l3, k) = map(int, input().split())
	if l1 > l2:
		(l1, l2) = (l2, l1)
	if l3 >= l1 and l2 >= l3:
		l31 = l3 + k
		l32 = l3 - k
		if l3 + k >= l2:
			l31 = l2
		if l3 - k <= l1:
			l32 = l1
		print(l2 - l1 - (l31 - l32))
	elif l3 > l2:
		if l3 - k <= l2 and l3 - k >= l1:
			print(l3 - k - l1)
		elif l3 - k > l2:
			print(l2 - l1)
		elif l3 - k < l1:
			print(0)
	elif l3 < l1:
		if l3 + k >= l1 and l3 + k <= l2:
			print(l2 - (l3 + k))
		elif l3 + k < l1:
			print(l2 - l1)
		elif l3 + k > l2:
			print(0)


t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	x = min(a, b)
	y = max(b, a)
	r1 = c - r
	r2 = c + r
	intsx = (max(x, r1), min(y, r2))
	print(max(0, y - x - max(0, intsx[1] - intsx[0])))


cases_str = input()
cases = int(cases_str)
for _ in range(cases):
	read = input()
	(a, b, c, r) = [int(x) for x in read.split(' ')]
	(a, b) = sorted([a, b])
	summ = 0
	if b < c - r:
		print(b - a)
		continue
	if a > c + r:
		print(b - a)
		continue
	print(max(0, c - r - a) + max(0, b - (c + r)))


t = int(input())
for x in range(0, t):
	strng = input()
	l1 = strng.split(' ')
	y = min(int(l1[0]), int(l1[1]))
	z = max(int(l1[0]), int(l1[1]))
	u = int(l1[2]) - int(l1[3])
	v = int(l1[2]) + int(l1[3])
	if u in range(y, z + 1) and v in range(y, z + 1):
		print(u - y + (z - v))
	elif u in range(y, z + 1) and v not in range(y, z + 1):
		print(u - y)
	elif u not in range(y, z + 1) and v in range(y, z + 1):
		print(z - v)
	elif u < y and v < y or (u > z and v > z):
		print(z - y)
	else:
		print('0')


t = int(input())
for i in range(t):
	(a, b, c, r) = input().split()
	(a, b, c, r) = [int(a), int(b), int(c), int(r)]
	if a > b:
		a = a + b
		b = a - b
		a = a - b
	s = c - r
	f = c + r
	ans = 0
	if a <= s and b >= f:
		ans = b - a - (f - s)
	if a > s and f <= b:
		ans = b - a - (f - a)
	if s > a and f > b:
		ans = b - a - (b - s)
	if s < a and f > b:
		ans = 0
	if s < a and f < a:
		ans = b - a
	if s > b and f > b:
		ans = b - a
	print(ans)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	r1 = c - r
	r2 = c + r
	x = 0
	if r1 <= a <= b <= r2:
		x = 0
	elif r1 <= r2 <= a <= b:
		x = b - a
	elif r1 <= a <= r2 <= b:
		x = b - r2
	elif a <= r1 <= r2 <= b:
		x = b - a - (r2 - r1)
	elif a <= r1 <= b <= r2:
		x = r1 - a
	elif a <= b <= r1 <= r2:
		x = b - a
	print(x)


import sys
t = int(sys.stdin.readline().rstrip())

def main():
	for _ in range(t):
		(a, b, c, r) = map(int, sys.stdin.readline().split())
		l = c - r
		r = c + r
		if a > b:
			(a, b) = (b, a)
		ans = min(max(0, l - a), b - a) + min(max(0, b - r), b - a)
		yield ans
ans = main()
print(*ans, sep='\n')


import sys
from collections import Counter
from math import *
for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		(a, b) = (b, a)
	res1 = max(a, c - r)
	res2 = min(b, c + r)
	print(max(0, b - a - max(0, res2 - res1)))


from array import array
from sys import stdin
import bisect
from itertools import *

def scan_gen():
	for line in stdin:
		yield from iter(line.split())
scan = scan_gen()

def nint():
	return int(next(scan))

def nintk(k):
	return tuple((nint() for _ in range(k)))

def nfloat():
	return float(next(scan))

def intar_init(size):
	return array('i', [0]) * size

def intar(size=None):
	if size == None:
		size = nint()
	arr = intar_init(size)
	for x in range(size):
		arr[x] = nint()
	return arr

def solve():
	t = nint()
	for _ in range(t):
		(a, b, c, r) = nintk(4)
		(a, b) = (min(a, b), max(a, b))
		aa = c - r
		bb = c + r
		ia = max(a, aa)
		ib = min(b, bb)
		print(b - a - max(0, ib - ia))
solve()


for i in range(int(input())):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if a >= c + d or b <= c - d:
		print(b - a)
	elif a <= c - d and b >= c + d:
		print(b - a - 2 * d)
	elif a > c - d and b < c + d:
		print('0')
	elif a <= c - d and b < c + d:
		print(c - d - a)
	elif a > c - d and b >= c + d:
		print(b - c - d)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(z, e) = ([], [])
	l = c - r
	r = c + r
	st = max(l, min(a, b))
	ed = min(r, max(a, b))
	f = abs(b - a) - max(0, ed - st)
	print(f)


t = int(input())
for zz in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	distance = b - a
	res = 0
	left = c - r
	right = c + r
	if left > a:
		res += left - a
	if right < b:
		res += b - right
	if right <= a or left >= b:
		res = distance
	print(res)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	point_l = c - r
	point_r = c + r
	ans = 0
	if point_r <= a or b <= point_l:
		ans = b - a
	else:
		if a < point_l:
			ans += point_l - a
		if point_r < b:
			ans += b - point_r
	print(ans)


for f in range(int(input())):
	f = [int(i) for i in input().split()]
	a = f[0]
	b = f[1]
	c = f[2]
	r = f[3]
	(a, b) = (min(a, b), max(a, b))
	if c + r <= a or c - r >= b:
		print(b - a)
	elif c <= a:
		print(max(b - c - r, 0))
	elif c >= b:
		print(max(c - a - r, 0))
	else:
		v = max(b - c - r, 0)
		print(v + max(c - a - r, 0))


import sys
t = int(input())
for tot in range(t):
	(a, b, c, d) = map(int, input().split())
	if a > b:
		a ^= b
		b ^= a
		a ^= b
	print(b - a - max(min(c + d, b) - max(a, c - d), 0))


t = int(input())
for T in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	total = abs(a - b)
	mn = c - r
	mx = c + r
	if a >= mn:
		if a <= mx:
			if b <= mx:
				total = 0
			else:
				total -= abs(a - mx)
	elif a <= mn and b >= mx:
		total -= abs(mn - mx)
	elif b >= mn:
		total -= abs(b - mn)
	total = max(total, 0)
	print(total)


for x in range(int(input())):
	case = input().split()
	case = list(map(int, case))
	mini = abs(min(case[0], case[1], case[2] - case[3])) + 1
	initial = min(case[0] + mini, case[1] + mini)
	final = max(case[1] + mini, case[0] + mini)
	upperb = case[2] + case[3] + mini
	lowerb = case[2] - case[3] + mini
	total = final - initial
	range = case[3] * 2
	if initial <= lowerb and final >= upperb:
		ans = total - range
	elif final > upperb and initial > lowerb and (upperb > initial):
		ans = final - upperb
	elif upperb > final and lowerb > initial and (final > lowerb):
		ans = lowerb - initial
	elif lowerb >= final or upperb <= initial:
		ans = total
	else:
		ans = 0
	print(ans)


t = input()
t = int(t)
for i in range(t):
	aux = input().split(' ')
	for i in range(4):
		aux[i] = int(aux[i])
	nums = [aux[0], aux[1]]
	nums.sort()
	cizqr = aux[2] - aux[3]
	cderr = aux[2] + aux[3]
	izq = False
	der = False
	distIZQ = 0
	distDER = 0
	numeros = [nums[0], 0, 0, nums[1]]
	if cizqr > nums[0] and cizqr < nums[1]:
		numeros[1] = cizqr
		izq = True
	if cderr > nums[0] and cderr < nums[1]:
		numeros[2] = cderr
		der = True
	if izq == True:
		distIZQ = ((numeros[0] - numeros[1]) ** 2) ** (1 / 2)
	if der == True:
		distDER = ((numeros[2] - numeros[3]) ** 2) ** (1 / 2)
	if cizqr <= numeros[0] and cderr >= numeros[3]:
		print(0)
		continue
	if der == False and izq == False:
		print(int(((numeros[0] - numeros[3]) ** 2) ** (1 / 2)))
		continue
	print(int(distIZQ + distDER))


n = input()
a = ''
for i in range(int(n)):
	a += input() + '\n'
for i in a.split('\n')[:-1]:
	(aa, bb, c, d) = list(map(int, i.split(' ')))
	a = min(aa, bb)
	b = max(aa, bb)
	base = abs(a - b)
	if c < a:
		base -= min(max(c + d - a, 0), base)
	elif c > b:
		base -= min(max(b - c + d, 0), base)
	else:
		base -= min(c - a, d)
		base -= min(b - c, d)
	print(base)


for t in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	(a, b) = (min(a, b), max(a, b))
	x = c - r
	y = c + r
	o = max(0, min(b, y) - max(a, x))
	print(b - a - o)


from collections import defaultdict as dd
import math
import sys

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))

def solve(a, b, c, r):
	if a > b:
		(a, b) = (b, a)
	if c - r <= a and c + r >= b:
		return 0
	if c - r >= b or c + r <= a:
		return b - a
	if a <= c - r and c + r <= b:
		return b - a - 2 * r
	if a <= c - r and c - r <= b:
		return c - r - a
	return b - (c + r)
T = nn()
for _ in range(T):
	(a, b, c, r) = mi()
	print(solve(a, b, c, r))


T = int(input())
for kase in range(T):
	(a, b, c, r) = [int(x) for x in input().split()]
	(a, b) = (min(a, b), max(a, b))
	(x, y) = (c - r, c + r)
	(u, v) = (max(a, x), min(b, y))
	print(b - a - max(0, v - u))


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	ct = b - a
	if c > b:
		ct -= max(0, b - c + r)
	elif c < a:
		ct -= max(0, c + r - a)
	else:
		if c - r < a:
			ct -= c - a
		else:
			ct -= r
		if c + r > b:
			ct -= b - c
		else:
			ct -= r
	print(max(ct, 0))


n = int(input())
for _ in range(n):
	(A, B, c, r) = map(int, input().split())
	b = max(A, B)
	a = A + B - b
	res = b - a
	if c - r > b or c + r < a:
		print(res)
	elif c - r >= a and c + r <= b:
		print(max(0, res - 2 * r))
	elif c + r > b and c - r >= a:
		print(max(0, c - r - a))
	else:
		print(max(0, b - c - r))


for i in range(int(input())):
	(a, b, c, r) = [int(x) for x in input().split(' ')]
	print(min(abs(a - b), max(0, abs(a - c) - r) + max(0, abs(b - c) - r)))


def per(a, b, c, d):
	if b < a:
		(a, b) = (b, a)
	return max(min(b, d) - max(a, c), 0)
v = int(input())
r = []
for i in range(v):
	(fr, to, st, rd) = list(map(int, input().split()))
	if fr > to:
		(fr, to) = (to, fr)
	r.append(int(to - fr))
	r[i] -= per(fr, to, st - rd, st + rd)
	r[i] = max(0, r[i])
for i in range(v):
	print(r[i])


for _ in range(int(input())):
	(a, b, c, r) = input().split(' ')
	(a, b, c, r) = (int(a), int(b), int(c), int(r))
	(x, y) = (min(a, b), max(a, b))
	count = 0
	if c >= x and c <= y:
		if c + r <= y:
			count += y - c - r
		if c - r >= x:
			count += c - r - x
	elif c >= y:
		if c - r >= x and c - r <= y:
			count += c - r - x
		elif c - r >= y:
			count += y - x
	elif c + r >= x and c + r <= y:
		count += y - c - r
	elif c + r <= x:
		count += y - x
	print(count)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	x = c - r
	y = c + r
	l = max(x, min(a, b))
	r = min(y, max(a, b))
	print(max(a, b) - min(a, b) - max(0, r - l))


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


def mi():
	return map(int, input().split())
for _ in range(int(input())):
	(a, c, b, r) = mi()
	(s, e) = (b - r, b + r)
	ans = 0
	(a, c) = (min(a, c), max(a, c))
	if a >= s and c <= e:
		print(0)
	elif a > e or c < s:
		print(c - a)
	elif a <= s:
		if c >= e:
			print(c - e + s - a)
		else:
			print(s - a)
	elif c >= e:
		if a > s:
			print(c - e)


def main():
	for _ in range(int(input())):
		(a, b, c, r) = map(int, input().split())
		(a, b) = sorted([a, b])
		if a <= c <= b:
			total = max(0, c - r - a) + max(0, b - (c + r))
		elif c > b:
			total = max(0, min(b - a, c - r - a))
		else:
			total = max(0, min(b - a, b - (c + r)))
		print(total)
main()


from math import *

def overlap(min1, max1, min2, max2):
	return max(0, min(max1, max2) - max(min1, min2))
t = int(input())
for _ in range(0, t):
	(a, b, c, r) = map(int, input().split())
	l = int(c - r)
	r = int(c + r)
	ret = abs(a - b) - overlap(min(a, b), max(a, b), l, r)
	print(ret)


t = int(input())
while t:
	t -= 1
	(a, b, c, r) = map(int, input().split())
	if a > b:
		x = a
		a = b
		b = x
	s = 0
	if a < c and b > c:
		if c - r >= a:
			s = s + c - r - a
		if c + r <= b:
			s = s + b - c - r
	elif c >= b:
		if c - r >= b:
			s = s + b - a
		elif c - r <= b and c - r > a:
			s = s + c - r - a
		elif c - r <= a:
			s = s + 0
	elif c <= a:
		if c + r <= a:
			s = s + b - a
		elif c + r > a and c + r < b:
			s = s + b - c - r
		elif c + r >= b:
			s = s + 0
	print(s)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	left = c - r
	right = c + r
	if b < left or right < a:
		ans = b - a
	elif left <= a and b <= right:
		ans = 0
	elif a <= left and right <= b:
		ans = left - a + b - right
	elif a <= left:
		ans = left - a
	elif right <= b:
		ans = b - right
	print(ans)
t = int(input())
for i in range(t):
	solve()


n = int(input())
for i in range(n):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	lower_lim = c - r
	upper_lim = c + r
	if lower_lim >= a and upper_lim <= b:
		lower_dist = lower_lim - a
		upper_dist = b - upper_lim
		print(lower_dist + upper_dist)
	elif lower_lim >= a and upper_lim > b:
		if lower_lim > b:
			print(b - a)
		else:
			print(lower_lim - a)
	elif lower_lim < a and upper_lim < b:
		if lower_lim < a and upper_lim < a:
			print(b - a)
		elif lower_lim < a and upper_lim < b:
			print(b - upper_lim)
	elif lower_lim < a and upper_lim > b:
		print(0)
	elif lower_lim > b or upper_lim < a:
		print(b - a)
	elif upper_lim <= b and lower_lim <= a:
		print(0)


t = input()
for _ in range(int(t)):
	(a, b, c, r) = map(int, input().split())
	maxx = max(a, b)
	minn = min(a, b)
	if c - r >= maxx and c + r >= maxx or (c + r <= minn and c - r <= minn):
		print(maxx - minn)
	else:
		if c - r > minn:
			minn = c - r - minn
		else:
			minn = 0
		if maxx > c + r:
			maxx = maxx - (c + r)
		else:
			maxx = 0
		print(minn + maxx)


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		mayor = a
		menor = b
	else:
		mayor = b
		menor = a
	resta = 0
	if c + r >= mayor and c - r <= menor:
		resta += abs(a - b)
	elif c + r <= menor and c - r <= menor:
		resta += 0
	elif c + r >= mayor and c - r >= mayor:
		resta += 0
	elif c + r >= mayor and c - r > menor:
		resta += abs(mayor - (c - r))
	elif c + r < mayor and c - r <= menor:
		resta += abs(menor - (c + r))
	elif c + r <= mayor and c - r >= menor:
		resta += abs(c - r - (c + r))
	print(abs(a - b) - resta)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	tt = abs(b - a)
	m1 = c - r
	m2 = c + r
	if m1 >= min(a, b) and m2 <= max(a, b):
		print(tt - 2 * r)
	elif m1 < min(a, b) and m2 <= max(a, b) and (m2 >= min(a, b)):
		print(tt - (m2 - min(a, b)))
	elif m1 <= max(a, b) and m2 > max(a, b) and (m1 >= min(a, b)):
		print(tt - (max(a, b) - m1))
	elif m1 <= min(a, b) and m2 >= max(a, b):
		print(0)
	else:
		print(tt)


t = int(input())
for x in range(t):
	l1 = [int(x) for x in input().split()]
	low = min(l1[0], l1[1])
	high = max(l1[1], l1[0])
	lcover = l1[2] - l1[3]
	hcover = l1[2] + l1[3]
	if lcover <= low and hcover >= high:
		print(0)
	elif lcover >= high or hcover <= low:
		print(high - low)
	elif lcover <= low and hcover < high:
		print(high - hcover)
	elif lcover > low and hcover >= high:
		print(lcover - low)
	elif lcover > low and hcover < high:
		print(high - hcover + lcover - low)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	if a > c - r and b < c + r:
		print(0)
	else:
		res = 0
		if a < c - r:
			res += min(b, c - r) - a
		if b > c + r:
			res += b - max(c + r, a)
		print(res)


import math
vv = int(input())
for k in range(vv):
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	time = b - a
	if c + r <= a or c - r >= b:
		print(time, flush=True)
	else:
		lwb = c - r
		upb = c + r
		upb = min(upb, b)
		lwb = max(lwb, a)
		time = time - (upb - lwb)
		print(time, flush=True)


t = int(input())
for i in range(0, t):
	(a, b, c, r) = map(int, input().split())
	if b < a:
		temp = b
		b = a
		a = temp
	if c - r >= b:
		print(abs(b - a))
	elif c + r <= a:
		print(abs(b - a))
	elif b <= c + r and c - r <= b:
		if a >= c - r:
			print(0)
		else:
			ans = abs(c - a)
			if ans >= r:
				print(ans - r)
			else:
				print(0)
	elif c - r >= a and c + r <= b:
		ans = abs(b - a)
		if ans >= 2 * r:
			print(ans - 2 * r)
		else:
			print(0)
	elif a >= c - r and a <= c + r:
		if b <= c + r:
			print(0)
		else:
			ans = abs(b - c)
			if ans >= r:
				print(ans - r)
			else:
				print(0)
	else:
		print(0)


from math import *
t = int(input())
for i in range(t):
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	total = b - a
	d = c - r
	e = c + r
	rng = range(a, b + 1)
	if d in rng and e in rng:
		print(abs(total) - 2 * r)
	elif d in rng:
		print(abs(total) - abs(b - d))
	elif e in rng:
		print(abs(total) - abs(e - a))
	elif d <= a and e >= b:
		print('0')
	else:
		print(abs(total))


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ml = c - r
	mr = c + r
	if ml > b or mr < a:
		print(b - a)
	else:
		right = max(0, b - mr)
		left = max(0, ml - a)
		ans = right + left
		print(ans)


num = int(input())
while num > 0:
	arr = list(map(int, input().split()))
	a = arr[0]
	b = arr[1]
	c = arr[2]
	r = arr[3]
	time = abs(b - a)
	lower = c - r
	upper = c + r
	if time == 0:
		print(0)
		num -= 1
		continue
	min_1 = min(a, b)
	max_1 = max(a, b)
	if min_1 <= lower:
		if max_1 >= upper and lower < max_1:
			time = time - upper + lower
		elif max_1 < upper and lower < max_1:
			time = time - max_1 + lower
		else:
			time = time
	elif max_1 > upper and min_1 <= upper:
		time = time - upper + min_1
	elif max_1 > upper and min_1 > upper:
		time = time
	else:
		time = 0
	print(time)
	num -= 1


t = int(input())
for i in range(t):
	p = list(map(int, input().split()))
	a = p[0]
	b = p[1]
	c = p[2]
	r = p[3]
	l = min(c - r, c + r)
	h = max(c + r, c - r)
	res = 0
	if a < l and b < l:
		res += abs(a - b)
	elif a > h and b > h:
		res += abs(a - b)
	else:
		if b < l:
			res += l - b
		elif b > h:
			res += b - h
		if a < l:
			res += l - a
		elif a > h:
			res += a - h
	print(res)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	ans = b - a
	if c - r <= a <= c + r and c - r <= b <= c + r:
		ans = 0
	elif a <= c - r <= b and a <= c + r <= b:
		ans -= 2 * r
	elif a <= c - r <= b:
		ans -= b - c + r
	elif a <= c + r <= b:
		ans -= c + r - a
	print(ans)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	(p1, p2) = (c - r, c + r)
	s = 0
	if p1 >= a:
		if p1 >= b:
			s = b - a
		elif p2 <= b:
			s = b - a - (p2 - p1)
		else:
			s = p1 - a
	elif p2 >= b:
		s = 0
	elif p2 >= a and p2 <= b:
		s = b - a - (p2 - a)
	else:
		s = b - a
	print(s)


ll = lambda : list(map(int, input().split()))

def o_r(a, b, c, d):
	return max(0, min(d, b) - max(a, c))
from math import *
for _ in range(int(input())):
	[a, b, c, r] = ll()
	(a, b) = (min(a, b), max(a, b))
	ans = b - a
	print(ans - o_r(a, b, c - r, c + r))


def solve():
	t = int(input())
	for _ in range(t):
		s = input()
		(a, b, c, r) = map(int, s.split())
		if a > b:
			(a, b) = (b, a)
		add1 = min(b - a, max(c - r - a, 0))
		add2 = min(b - a, max(b - (c + r), 0))
		print(add1 + add2)
solve()


x = int(input())
for i in range(x):
	y = input().split()
	(a, b, c, r) = [int(i) for i in y]
	lis = [a, b]
	lis.sort()
	lis1 = [c - r, c + r]
	lis1.sort()
	nb = 0
	if lis1[0] >= lis[0] and lis1[1] <= lis[1]:
		nb = lis1[1] - lis1[0] + 1
	elif lis1[0] > lis[0]:
		nb = lis[1] - lis1[0] + 1
	elif lis1[1] < lis[1]:
		nb = lis1[1] - lis[0] + 1
	elif lis[0] >= lis1[0] and lis[1] <= lis1[1]:
		nb = lis[1] - lis[0] + 1
	if lis1[0] >= lis[1] or lis1[1] <= lis[0]:
		nb = 0
	if nb > 0:
		print(abs(a - b) + 1 - nb)
	elif nb == 0 and a != b:
		print(lis[1] - lis[0])
	elif nb == 0 and a == b:
		print(0)


t = int(input())
for i in range(t):
	ls = list(map(int, input().split()))
	(a, b, c, r) = (ls[0], ls[1], ls[2], ls[3])
	(l, h) = (c - r, c + r)
	if a > b:
		(a, b) = (b, a)
	if h <= a:
		if b - a > 0:
			print(b - a)
		else:
			print(0)
	elif l <= a and a <= h:
		if b - h > 0:
			print(b - h)
		else:
			print(0)
	elif a <= l <= h <= b:
		if l + b - a - h > 0:
			print(l - a + (b - h))
		else:
			print(0)
	elif l <= b and h >= b:
		if l - a > 0:
			print(l - a)
		else:
			print(0)
	else:
		print(b - a)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	(a, b, c, r) = multi_int_input()
	left = c - r
	right = c + r
	if a == b:
		print(0)
	else:
		if a > b:
			(a, b) = (b, a)
		time = 0
		if left > a and right < b:
			time = left - a + (b - right)
		elif left > b or right < a:
			time = abs(b - a)
		elif left <= a and right >= b:
			time = 0
		elif right >= b and left <= b:
			time = left - a
		else:
			time = b - right
		print(time)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	(a, b) = (min(a, b), max(a, b))
	(x, y) = (c - r, c + r)
	if a <= x <= b and a <= y <= b:
		print(b - a - 2 * r)
	elif a <= x <= b:
		print(x - a)
	elif a <= y <= b:
		print(b - y)
	elif x < a < b < y:
		print(0)
	else:
		print(b - a)


t = int(input())
while t:
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	d = 0
	if a <= c and c <= b:
		d += max(0, c - r - a)
		d += max(0, b - (c + r))
	elif c > b:
		mid = min(b, c - r)
		d = max(0, mid - a)
	else:
		mid = max(a, c + r)
		d = max(0, b - mid)
	print(d)
	t -= 1


from collections import deque
import sys
import math
input = sys.stdin.buffer.readline
q = int(input())
for _ in range(q):
	(a, b, c, r) = map(int, input().split())
	a1 = min(a, b)
	b1 = max(a, b)
	(a, b) = (a1, b1)
	d = b - a
	tot = 0
	if a <= c <= b:
		if c + r < b:
			tot += b - (c + r)
		if c - r > a:
			tot += c - r - a
	elif c <= a:
		if c + r > a:
			if c + r < b:
				tot += b - (c + r)
		else:
			tot = b - a
	elif c - r < b:
		if c - r > a:
			tot += c - r - a
	else:
		tot = b - a
	print(tot)


for _ in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	mn1 = min(a, b)
	mx1 = max(a, b)
	mn2 = min(c - r, c + r)
	mx2 = max(c - r, c + r)
	x = 0
	if mn1 <= mn2:
		x = min(mn2 - mn1, mx1 - mn1)
	y = 0
	if mx1 >= mx2:
		y = min(mx1 - mx2, mx1 - mn1)
	print(x + y)


t = int(input())
for i in range(t):
	(a, b, c, r) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	print(abs(a - b) - abs(min(b, max(a, c + r)) - max(a, min(b, c - r))))


for i in range(int(input())):
	(a, b, c, r) = map(int, input().split())
	cnt = 0
	beg = max(c - r, min(a, b))
	end = min(c + r, max(a, b))
	print(abs(a - b) - max(0, end - beg))


for _ in range(int(input())):
	(a, b, c, r) = list(map(int, input().split()))
	if a > b:
		(a, b) = (b, a)
	if c - r <= a <= c + r and c - r <= b <= c + r:
		ans = b - a
	elif c - r <= a <= c + r:
		ans = c + (r - a)
	elif c - r <= b <= c + r:
		ans = b - (c - r)
	elif a <= c - r and b >= c + r:
		ans = 2 * r
	else:
		ans = 0
	print(b - a - ans)


cases = int(input())
for i in range(cases):
	(a, b, c, r) = [int(x) for x in input().split()]
	if a > b:
		(a, b) = (b, a)
	start = c - r
	end = c + r
	inter = 0
	if end <= a or start >= b:
		inter = 0
	if start <= a and end >= b:
		inter = b - a
	if start > a and end < b:
		inter = end - start
	elif a < start < b:
		inter = b - start
	elif a < end < b:
		inter = end - a
	print(b - a - inter)


t = int(input())
for i in range(0, t):
	(a, b, c, r) = map(int, input().split())
	s = 0
	x = c - r
	y = c + r
	if a < x and b < x or (a > y and b > y):
		s = s + abs(b - a)
	elif a < x and b >= x and (b <= y):
		s = s + abs(x - a)
	elif a > y and b >= x and (b <= y):
		s = s + abs(a - y)
	elif a >= x and a <= y and (b < x):
		s = s + abs(x - b)
	elif a >= x and a <= y and (b > y):
		s = s + abs(b - y)
	elif a < x and b > y:
		s = s + abs(x - a)
		s = s + abs(b - y)
	elif b < x and a > y:
		s = s + abs(x - b)
		s = s + abs(a - y)
	else:
		s = 0
	print(s)


t = int(input())
result = []
for i in range(t):
	ar = input().split()
	(a, b, c, r) = (int(ar[0]), int(ar[1]), int(ar[2]), int(ar[3]))
	if a > b:
		(a, b) = (b, a)
	left = c - r
	right = c + r
	if left <= a and right >= b:
		result.append(0)
	elif left > a and right >= b and (left < b):
		result.append(left - a)
	elif left <= a and right < b and (right > a):
		result.append(b - right)
	elif left > a and right < b:
		result.append(left - a + (b - right))
	else:
		result.append(b - a)
for r in result:
	print(r)