#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long mod) {
  if (b == 0 || a == 1) {
    if (mod == 1)
      return 0;
    else
      return 1;
  }
  if (b % 2 == 0) {
    long long k = powmod(a, b / 2, mod);
    return (k * k) % mod;
  } else {
    long long k = powmod(a, b / 2, mod);
    return ((k * k) % mod * a) % mod;
  }
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  if (b == 0) return a;
  if (a > b)
    return gcd(a % b, b);
  else
    return gcd(b % a, a);
}
long long prime(long long p) {
  if (p < 4) return true;
  if (p % 2 == 0) return false;
  if (p % 3 == 0) return false;
  for (long long i = 5; i * i <= p; i += 6) {
    if (!(p % i)) return i;
    if (!(p % (i + 2))) return false;
  }
  return true;
}
long long inv(long long a, long long mod) { return powmod(a, mod - 2, mod); }
void solve() {
  long long a, b, c, r;
  cin >> a >> b >> c >> r;
  if (a > b) swap(a, b);
  if (c <= b && c >= a) {
    long long ans = 0;
    ans = min(r, c - a) + min(b - c, r);
    cout << b - a - ans << "\n";
    return;
  }
  if (c <= a)
    cout << b - a - max(0LL, min(b - a, r - a + c)) << "\n";
  else
    cout << b - a - max(0LL, min(b - a, r + b - c)) << "\n";
  return;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tututu;
  tututu = 1;
  cin >> tututu;
  for (long long qwerty = 0; qwerty < tututu; qwerty++) solve();
  return 0;
}
